feat: refine wooden fish runtime generation
This commit is contained in:
@@ -271,4 +271,62 @@ describe('dev scheduler spacetime refresh', () => {
|
||||
expect(runner.waitForSpacetime).not.toHaveBeenCalled();
|
||||
expect(runner.publishSpacetimeModule).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('启动 api-server 前为空 token 自动创建本地 Web identity', async () => {
|
||||
const {explicitOptions, options} = parseArgs([], {
|
||||
GENARRATIVE_SPACETIME_TOKEN: '',
|
||||
});
|
||||
const runner = new DevRunner(options, {}, explicitOptions);
|
||||
runner.state.spacetimeServer = 'http://127.0.0.1:3101';
|
||||
globalThis.fetch = vi.fn(async () => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
text: async () =>
|
||||
JSON.stringify({
|
||||
identity: 'c200localidentity',
|
||||
token: 'local-web-token',
|
||||
}),
|
||||
})) as unknown as typeof fetch;
|
||||
|
||||
await runner.ensureApiServerSpacetimeToken();
|
||||
|
||||
expect(runner.baseEnv.GENARRATIVE_SPACETIME_TOKEN).toBe('local-web-token');
|
||||
expect(globalThis.fetch).toHaveBeenCalledWith(
|
||||
'http://127.0.0.1:3101/v1/identity',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('本地 SpacetimeDB 不信任 env 文件中的陈旧 token', async () => {
|
||||
const originalToken = process.env.GENARRATIVE_SPACETIME_TOKEN;
|
||||
delete process.env.GENARRATIVE_SPACETIME_TOKEN;
|
||||
try {
|
||||
const {explicitOptions, options} = parseArgs([], {
|
||||
GENARRATIVE_SPACETIME_TOKEN: 'stale-env-file-token',
|
||||
});
|
||||
const runner = new DevRunner(options, {GENARRATIVE_SPACETIME_TOKEN: 'stale-env-file-token'}, explicitOptions);
|
||||
runner.state.spacetimeServer = 'http://127.0.0.1:3101';
|
||||
globalThis.fetch = vi.fn(async () => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
text: async () =>
|
||||
JSON.stringify({
|
||||
identity: 'c200freshidentity',
|
||||
token: 'fresh-web-token',
|
||||
}),
|
||||
})) as unknown as typeof fetch;
|
||||
|
||||
await runner.ensureApiServerSpacetimeToken();
|
||||
|
||||
expect(runner.baseEnv.GENARRATIVE_SPACETIME_TOKEN).toBe('fresh-web-token');
|
||||
} finally {
|
||||
if (originalToken === undefined) {
|
||||
delete process.env.GENARRATIVE_SPACETIME_TOKEN;
|
||||
} else {
|
||||
process.env.GENARRATIVE_SPACETIME_TOKEN = originalToken;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user