feat: 完善敲木鱼玩法模板链路
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {mkdtempSync, rmSync, writeFileSync} from 'node:fs';
|
||||
import {mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs';
|
||||
import {tmpdir} from 'node:os';
|
||||
import {join} from 'node:path';
|
||||
|
||||
@@ -6,10 +6,13 @@ import {afterEach, describe, expect, test, vi} from 'vitest';
|
||||
|
||||
import {
|
||||
DevRunner,
|
||||
assertReusableSpacetimeProcessVersionMatchesWorkspace,
|
||||
assertSpacetimeToolVersionMatchesWorkspace,
|
||||
buildSpacetimePublishArgs,
|
||||
createDevServerSpawnOptions,
|
||||
createWatchConfigs,
|
||||
isSpacetimePublishPermissionError,
|
||||
parseSpacetimeToolVersion,
|
||||
parseArgs,
|
||||
shouldAcceptWatchEvent,
|
||||
} from './dev.mjs';
|
||||
@@ -21,6 +24,15 @@ afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
function workspaceSpacetimeVersionForTest() {
|
||||
const manifestText = readFileSync('server-rs/Cargo.toml', 'utf8');
|
||||
const match = /^spacetimedb\s*=\s*"([^"]+)"/mu.exec(manifestText);
|
||||
if (!match) {
|
||||
throw new Error('无法读取测试用 SpacetimeDB 版本');
|
||||
}
|
||||
return match[1];
|
||||
}
|
||||
|
||||
describe('dev scheduler argument routing', () => {
|
||||
test('完整 dev 栈覆盖前端代理到本次解析出的 api-server 地址', () => {
|
||||
const {command, explicitOptions, options} = parseArgs([], {
|
||||
@@ -104,6 +116,11 @@ describe('dev scheduler spacetime reuse guard', () => {
|
||||
try {
|
||||
writeFileSync(join(tempDir, 'dev-spacetime-url'), 'http://127.0.0.1:3199\n', 'utf8');
|
||||
writeFileSync(join(tempDir, 'spacetime.pid'), `${process.pid}\n`, 'utf8');
|
||||
writeFileSync(
|
||||
join(tempDir, 'dev-spacetime-tool-version'),
|
||||
`${workspaceSpacetimeVersionForTest()}\n`,
|
||||
'utf8',
|
||||
);
|
||||
globalThis.fetch = vi.fn(async () => ({status: 200})) as unknown as typeof fetch;
|
||||
|
||||
const {command, explicitOptions, options} = parseArgs(
|
||||
@@ -126,6 +143,11 @@ describe('dev scheduler spacetime reuse guard', () => {
|
||||
const tempDir = mkdtempSync(join(tmpdir(), 'genarrative-spacetime-reuse-'));
|
||||
try {
|
||||
writeFileSync(join(tempDir, 'spacetime.pid'), `${process.pid}\n`, 'utf8');
|
||||
writeFileSync(
|
||||
join(tempDir, 'dev-spacetime-tool-version'),
|
||||
`${workspaceSpacetimeVersionForTest()}\n`,
|
||||
'utf8',
|
||||
);
|
||||
globalThis.fetch = vi.fn(async () => ({status: 200})) as unknown as typeof fetch;
|
||||
|
||||
const {command, explicitOptions, options} = parseArgs(
|
||||
@@ -212,6 +234,40 @@ describe('dev scheduler watch routing', () => {
|
||||
});
|
||||
|
||||
describe('dev scheduler spacetime refresh', () => {
|
||||
test('解析 spacetime --version 输出里的 tool version', () => {
|
||||
const version = parseSpacetimeToolVersion(`
|
||||
A new version of SpacetimeDB is available: v2.2.0 (current: v2.1.0)
|
||||
spacetimedb tool version 2.2.0; spacetimedb-lib version 2.2.0;
|
||||
`);
|
||||
|
||||
expect(version).toBe('2.2.0');
|
||||
});
|
||||
|
||||
test('本机 spacetime 版本和 workspace 锁定版本不一致时直接报清楚', () => {
|
||||
expect(() =>
|
||||
assertSpacetimeToolVersionMatchesWorkspace({
|
||||
toolVersion: '2.1.0',
|
||||
workspaceVersion: '2.2.0',
|
||||
}),
|
||||
).toThrow('procedure 返回值 BSATN 反序列化失败');
|
||||
});
|
||||
|
||||
test('复用本地 SpacetimeDB standalone 前校验启动时版本记录', () => {
|
||||
const tempDir = mkdtempSync(join(tmpdir(), 'genarrative-spacetime-version-'));
|
||||
try {
|
||||
writeFileSync(join(tempDir, 'dev-spacetime-tool-version'), '2.1.0\n', 'utf8');
|
||||
|
||||
expect(() =>
|
||||
assertReusableSpacetimeProcessVersionMatchesWorkspace({
|
||||
dataDir: tempDir,
|
||||
serverUrl: 'http://127.0.0.1:3101',
|
||||
}),
|
||||
).toThrow('SpacetimeDB procedure 调用超时');
|
||||
} finally {
|
||||
rmSync(tempDir, {recursive: true, force: true});
|
||||
}
|
||||
});
|
||||
|
||||
test('本地发布 403 时识别为身份权限问题,避免误杀 standalone', () => {
|
||||
const error = new Error(
|
||||
'Pre-publish check failed with status 403 Forbidden: c200... is not authorized to perform action on database c200...: update database',
|
||||
|
||||
Reference in New Issue
Block a user