Some checks failed
Deploy Production / Build, push, deploy, verify (push) Has been cancelled
- 移除已迁移业务 AppData 运行时 fallback,改走领域 API 和关系表快读 - 补齐需求产品负责人、版本计划任务 JSON 和成员 username 回填迁移 - 统一治理字典入口,并补充 AI provider、数据源契约和领域服务测试 Co-Authored-By: Codex GPT-5 <codex@openai.com>
91 lines
4.4 KiB
TypeScript
91 lines
4.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import test from 'node:test';
|
|
|
|
const testCaseStore = () => readFileSync(join(process.cwd(), 'stores/useTestCaseStore.ts'), 'utf8');
|
|
const bugStore = () => readFileSync(join(process.cwd(), 'stores/useBugStore.ts'), 'utf8');
|
|
const testCaseTab = () => readFileSync(join(process.cwd(), 'components/test-case/TestCaseTab.tsx'), 'utf8');
|
|
const bugTab = () => readFileSync(join(process.cwd(), 'components/bug/BugTab.tsx'), 'utf8');
|
|
|
|
function storeMethodBody(text: string, name: string) {
|
|
const implementationStart = text.indexOf('export const');
|
|
assert.notEqual(implementationStart, -1, 'missing store implementation');
|
|
const start = text.indexOf(` ${name}:`, implementationStart);
|
|
assert.notEqual(start, -1, `missing store method ${name}`);
|
|
|
|
let depth = 0;
|
|
let sawFirstBrace = false;
|
|
for (let i = start; i < text.length; i += 1) {
|
|
const char = text[i];
|
|
if (char === '{') {
|
|
depth += 1;
|
|
sawFirstBrace = true;
|
|
}
|
|
if (char === '}') {
|
|
depth -= 1;
|
|
if (sawFirstBrace && depth === 0) return text.slice(start, i + 1);
|
|
}
|
|
}
|
|
throw new Error(`could not extract store method ${name}`);
|
|
}
|
|
|
|
test('test case store uses domain APIs for version-scoped writes', () => {
|
|
const text = testCaseStore();
|
|
const fetchTestCases = storeMethodBody(text, 'fetchTestCases');
|
|
|
|
assert.match(text, /from '@\/lib\/domain-api'/);
|
|
assert.match(fetchTestCases, /listTestCasesByVersionId\(options\.versionId\)/);
|
|
assert.match(fetchTestCases, /!options\?\.versionId && !options\?\.force/);
|
|
assert.match(storeMethodBody(text, 'createTestCase'), /createTestCaseByVersionId\(tc\.versionId,/);
|
|
assert.match(storeMethodBody(text, 'createTestCases'), /createTestCasesByVersionId\(created\[0\]\.versionId,/);
|
|
assert.match(storeMethodBody(text, 'updateTestCase'), /updateTestCaseByVersionId\(versionId, id,/);
|
|
assert.match(storeMethodBody(text, 'changeStatus'), /updateTestCaseStatusByVersionId\(tc\.versionId,/);
|
|
assert.doesNotMatch(storeMethodBody(text, 'createTestCase'), /saveServerData\('test-cases'/);
|
|
assert.doesNotMatch(storeMethodBody(text, 'updateTestCase'), /saveServerData\('test-cases'/);
|
|
});
|
|
|
|
test('bug store uses domain APIs for version-scoped writes', () => {
|
|
const text = bugStore();
|
|
const fetchBugs = storeMethodBody(text, 'fetchBugs');
|
|
|
|
assert.match(text, /from '@\/lib\/domain-api'/);
|
|
assert.match(fetchBugs, /listBugsByVersionId\(options\.versionId\)/);
|
|
assert.match(fetchBugs, /!options\?\.versionId && !options\?\.force/);
|
|
assert.match(storeMethodBody(text, 'createBug'), /createBugByVersionId\(bug\.versionId,/);
|
|
assert.match(storeMethodBody(text, 'updateBug'), /updateBugByVersionId\(versionId, id,/);
|
|
assert.match(storeMethodBody(text, 'changeStatus'), /updateBugStatusByVersionId\(bug\.versionId,/);
|
|
assert.match(storeMethodBody(text, 'transferBug'), /transferBugByVersionId\(bug\.versionId,/);
|
|
assert.doesNotMatch(storeMethodBody(text, 'createBug'), /saveServerData\('bugs'/);
|
|
assert.doesNotMatch(storeMethodBody(text, 'updateBug'), /saveServerData\('bugs'/);
|
|
});
|
|
|
|
test('workspace test case and bug drawers load version-scoped relation data', () => {
|
|
const page = readFileSync(join(process.cwd(), 'app/workspace/page.tsx'), 'utf8');
|
|
|
|
assert.match(page, /fetchTestCases\(\{ versionId: item\.versionId \}\)/);
|
|
assert.match(page, /fetchBugs\(\{ versionId: item\.versionId \}\)/);
|
|
assert.doesNotMatch(page, /item\.type === 'testCase' && !testCasesLoaded/);
|
|
assert.doesNotMatch(page, /item\.type === 'bug' && !bugsLoaded/);
|
|
assert.doesNotMatch(page, /pendingLoads\.push\(fetchTestCases\(\)\);/);
|
|
assert.doesNotMatch(page, /pendingLoads\.push\(fetchBugs\(\)\);/);
|
|
});
|
|
|
|
test('test case tab fallback fetches current version relation partitions', () => {
|
|
const text = testCaseTab();
|
|
|
|
assert.match(text, /fetchTestCases\(\{ versionId \}\)/);
|
|
assert.match(text, /fetchBugs\(\{ versionId \}\)/);
|
|
assert.doesNotMatch(text, /if \(!scopedVersionCases\) fetchTestCases\(\);/);
|
|
assert.doesNotMatch(text, /if \(!scopedVersionBugs\) fetchBugs\(\);/);
|
|
});
|
|
|
|
test('bug tab fallback fetches current version relation partitions', () => {
|
|
const text = bugTab();
|
|
|
|
assert.match(text, /fetchBugs\(\{ versionId \}\)/);
|
|
assert.match(text, /fetchTestCases\(\{ versionId \}\)/);
|
|
assert.doesNotMatch(text, /if \(!scopedVersionBugs\) fetchBugs\(\);/);
|
|
assert.doesNotMatch(text, /if \(!versionTestCases\) fetchTestCases\(\);/);
|
|
});
|