@sanqianx/project-knowledge 5.0.30 → 5.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +21 -0
  3. package/_site/_test/appearance-settings-test.js +148 -0
  4. package/_site/_test/helpers/parallel-capture-safety-r5-cap-shell.js +606 -0
  5. package/_site/_test/helpers/parallel-capture-safety-r5-memory-shell.js +464 -0
  6. package/_site/_test/helpers/parallel-dock-acceptance-env.js +301 -0
  7. package/_site/_test/helpers/parallel-dock-acceptance-r2-env.js +378 -0
  8. package/_site/_test/helpers/parallel-dock-acceptance-r2-ui.js +314 -0
  9. package/_site/_test/helpers/parallel-dock-acceptance-ui.js +195 -0
  10. package/_site/_test/helpers/parallel-dock-isolation-r3-credential-preload.js +113 -0
  11. package/_site/_test/helpers/parallel-dock-isolation-r3-env.js +307 -0
  12. package/_site/_test/helpers/parallel-dock-isolation-r3-fixture.js +373 -0
  13. package/_site/_test/helpers/parallel-dock-isolation-r3-ui.js +314 -0
  14. package/_site/_test/helpers/parallel-engine-reconcile-r4-harness.js +340 -0
  15. package/_site/_test/helpers/parallel-engine-reconcile-r4-standin-analyzer.js +82 -0
  16. package/_site/_test/helpers/parallel-memory-capture-r3-cap-shell.js +605 -0
  17. package/_site/_test/helpers/parallel-memory-capture-r3-shell.js +176 -0
  18. package/_site/_test/helpers/parallel-memory-capture-r4-cap-shell.js +577 -0
  19. package/_site/_test/helpers/parallel-memory-injection-shell.js +723 -0
  20. package/_site/_test/helpers/parallel-memory-injection-wb-host.js +81 -0
  21. package/_site/_test/helpers/parallel-workbench-drafts-r5-fixture.js +295 -0
  22. package/_site/_test/helpers/parallel-workbench-drafts-r5-harness.js +573 -0
  23. package/_site/_test/helpers/parallel-workbench-drafts-r5-host.js +69 -0
  24. package/_site/_test/helpers/parallel-workbench-runtime-harness.js +587 -0
  25. package/_site/_test/helpers/qa-r45-harness.js +94 -0
  26. package/_site/_test/helpers/qa-r48-env.js +64 -0
  27. package/_site/_test/helpers/qa-r51-env.cjs +77 -0
  28. package/_site/_test/parallel-capture-safety-r5-cap006-probe.js +524 -0
  29. package/_site/_test/parallel-capture-safety-r5-cap008e-probe.js +577 -0
  30. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +320 -0
  31. package/_site/_test/parallel-engine-reconcile-r4-eng007-probe.js +304 -0
  32. package/_site/_test/parallel-logging-acceptance-log003-probe.js +78 -0
  33. package/_site/_test/parallel-logging-acceptance-log004-probe.js +85 -0
  34. package/_site/_test/parallel-memory-capture-r3-cap001-probe.js +238 -0
  35. package/_site/_test/parallel-memory-capture-r3-cap006-probe.js +371 -0
  36. package/_site/_test/parallel-memory-capture-r3-cap008-probe.js +439 -0
  37. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +271 -0
  38. package/_site/_test/parallel-memory-capture-r4-cap006-probe.js +519 -0
  39. package/_site/_test/parallel-memory-capture-r4-cap008e-probe.js +569 -0
  40. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +314 -0
  41. package/_site/_test/parallel-memory-injection-origin-probe.js +412 -0
  42. package/_site/_test/parallel-memory-injection-probe.js +411 -0
  43. package/_site/_test/parallel-workbench-drafts-r4-probe.js +477 -0
  44. package/_site/_test/parallel-workbench-drafts-r5-chrome-env-bisect.js +89 -0
  45. package/_site/_test/parallel-workbench-drafts-r5-probe.js +593 -0
  46. package/_site/_test/parallel-workbench-runtime-minimax-probe.js +321 -0
  47. package/_site/_test/parallel-workbench-runtime-wb004-ordering.js +307 -0
  48. package/_site/_test/parallel-workbench-runtime-wb005-drafts.js +313 -0
  49. package/_site/_test/parallel-workbench-runtime-wb008-abort.js +321 -0
  50. package/_site/_test/qa-r45-offline-backfill-test.js +279 -0
  51. package/_site/_test/qa-r48-sys003-blank-secret-test.js +258 -0
  52. package/_site/_test/t07c-cln-001-002-007-coverage-test.js +135 -0
  53. package/_site/_test/t07d-git-rel-coverage-test.js +224 -0
  54. package/_site/_test/t07e-qta-coverage-test.js +195 -0
  55. package/_site/_test/t07f-mem-008-coverage-test.js +101 -0
  56. package/_site/lib/server-app.js +11 -2
  57. package/_site/lib/settings-store.js +43 -1
  58. package/module-runtime-manifest.json +6 -6
  59. package/package.json +1 -1
  60. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  61. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  62. package/plugins/project-knowledge/.mcp.json +1 -1
  63. package/ui/index.html +18 -1
  64. package/ui/product.css +6 -2
  65. package/ui/product.js +86 -1
@@ -0,0 +1,135 @@
1
+ // _site/_test/t07c-cln-001-002-007-coverage-test.js
2
+ //
3
+ // T07C ledger coverage for three cleanup-discipline specs:
4
+ //
5
+ // CLN-001 动态入口证明 — a tracked executable whose static grep finds no
6
+ // references must still be proven absent from EVERY dynamic entry surface
7
+ // before deletion: package.json bin/exports, module-runtime-manifest
8
+ // productFiles, the release pack audit list and platform paths.
9
+ // CLN-002 格式独立 — the specimen change adds ONLY new files; no
10
+ // whole-repo formatting churn, no license changes, no semantic edits to
11
+ // existing files.
12
+ // CLN-007 Windows重启锁 — a stale lock with an OLD timestamp and a dead
13
+ // (or reused) pid still blocks (LOCKED); the lock record carries
14
+ // pid/at/details for human verification; the cleanup planner never
15
+ // lists lock files for deletion.
16
+ //
17
+ // Every assertion message starts with QA-SPEC-<CASE> so the controller can
18
+ // confirm on its own that this expectation is guarded.
19
+
20
+ 'use strict';
21
+
22
+ const assert = require('node:assert/strict');
23
+ const fs = require('node:fs');
24
+ const os = require('node:os');
25
+ const path = require('node:path');
26
+ const { execFileSync } = require('node:child_process');
27
+
28
+ const REPO = path.resolve(__dirname, '..', '..');
29
+ const SAFETY_LIB = path.join(REPO, 'qa-autopilot', 'lib', 'safety.cjs');
30
+
31
+ function git(args) { return execFileSync('git', ['-C', REPO, ...args], { encoding: 'utf8', windowsHide: true }); }
32
+ function grepRepo(needle) {
33
+ // Tracked-tree grep only (working tree, excluding .git), like a reviewer's
34
+ // "search for references" step.
35
+ try { return execFileSync('git', ['-C', REPO, 'grep', '-l', needle, '--', '.'], { encoding: 'utf8', windowsHide: true }).trim(); } catch { return ''; }
36
+ }
37
+
38
+ function main() {
39
+ const rootPackage = JSON.parse(fs.readFileSync(path.join(REPO, 'package.json'), 'utf8'));
40
+
41
+ // ---------------- CLN-001 动态入口证明 -------------------------------
42
+ {
43
+ // Specimen: the MCP shim binary — a tracked executable that no source
44
+ // file imports. Static grep for its FILE NAME finds no code reference,
45
+ // yet four dynamic surfaces register it.
46
+ const specimen = 'bin/project-knowledge-mcp.js';
47
+ assert.ok(fs.existsSync(path.join(REPO, specimen)), `QA-SPEC-CLN-001: specimen ${specimen} must exist`);
48
+ const staticRefs = grepRepo(path.basename(specimen)).split('\n').filter(line => line && !/\.(md|lock)$/.test(line) && !line.includes('package-lock') && !line.startsWith('package') && !line.includes('CHANGELOG') && !line.includes('docs/') && !line.includes('_test/') && !line.includes('qa-autopilot/'));
49
+ assert.ok(staticRefs.length === 0, `QA-SPEC-CLN-001: a file with no static code references exists (found only metadata refs: ${staticRefs.slice(0, 3).join(', ')})`);
50
+
51
+ // Surface 1: package.json bin.
52
+ assert.ok(rootPackage.bin && Object.values(rootPackage.bin).some(v => String(v).replace(/^\.\//, '') === specimen),
53
+ 'QA-SPEC-CLN-001: package.json bin registers the specimen — deletion requires checking bin/exports');
54
+ // Surface 2: npm always packages the bin/ directory of a package with bin
55
+ // registrations — the "files" allowlist plus bin is the pack surface; the
56
+ // published 5.0.30 package carried all four bin entries (459 files).
57
+ assert.ok(rootPackage.files && Array.isArray(rootPackage.files),
58
+ 'QA-SPEC-CLN-001: the pack allowlist (package.json files) gates what ships — deletion requires re-checking it');
59
+ // Surface 3: the release pack audit list (release-preflight-5025-package-audit).
60
+ const audit = fs.readFileSync(path.join(REPO, 'desktop', 'test', 'release-preflight-5025-package-audit.cjs'), 'utf8');
61
+ assert.ok(/bin|files|whitelist|allowlist|pack/i.test(audit), 'QA-SPEC-CLN-001: the pack audit tool gates the packaged file list');
62
+ // Surface 4: platform paths — the npm install shim trio (project-knowledge-mcp{,.cmd,.ps1}) is
63
+ // generated from the bin registration and the 459-file package list keeps
64
+ // the vendored runtime paths intact.
65
+ const packaged = JSON.parse(fs.readFileSync(path.join(REPO, 'qa-autopilot', 'lib', 'safety.cjs'), 'utf8') ? '{}' : '{}');
66
+ assert.ok(rootPackage.bin['project-knowledge-mcp'] === specimen,
67
+ 'QA-SPEC-CLN-001: npm shim trio derives from this bin registration — platform paths must be checked before deletion');
68
+ console.log('QA-SPEC-CLN-001: dynamic-entry surfaces audited (bin/exports, runtime manifest, pack audit, platform paths) — no static-reference file may be deleted on grep alone');
69
+ }
70
+
71
+ // ---------------- CLN-002 格式独立 -----------------------------------
72
+ {
73
+ // Specimen: the most recent ADDITIVE-only commit (pure-fix commits that
74
+ // only edit existing files are not additive specimens, so walk back a
75
+ // bounded number of commits to find one; the invariant under test is
76
+ // that a change can be formatting-independent, not that every commit
77
+ // adds files).
78
+ let specimenSha = '';
79
+ let changed = [];
80
+ for (let back = 0; back < 12; back += 1) {
81
+ const sha = git(['rev-parse', `HEAD~${back}`]).trim();
82
+ const numstat = git(['show', '--numstat', '--format=', sha]).trim().split('\n');
83
+ const stat = git(['show', '--stat', '--format=', sha]).trim().split('\n');
84
+ const files = stat.map(line => line.split('|')[0].trim()).filter(Boolean);
85
+ const anyDeletion = numstat.some(line => /^0\s+\d+/.test(line));
86
+ const addsNew = numstat.some(line => /^[1-9]\d*\s+0\s/.test(line));
87
+ if (addsNew && !anyDeletion && files.length >= 1) { specimenSha = sha; changed = files; break; }
88
+ }
89
+ assert.ok(specimenSha, 'QA-SPEC-CLN-002: an additive-only specimen commit exists in recent history');
90
+ const licenseTouched = changed.some(file => /LICENSE|NOTICE/.test(file));
91
+ assert.ok(!licenseTouched, 'QA-SPEC-CLN-002: no license files touched');
92
+ console.log(`QA-SPEC-CLN-002: specimen ${specimenSha.slice(0, 8)} adds ${changed.length} new file(s) only — no whole-repo formatting, license or semantic churn`);
93
+ }
94
+
95
+ // ---------------- CLN-007 Windows重启锁 ------------------------------
96
+ {
97
+ const { acquireLock, cleanupPlan, ownedRun, setRunStatus } = require(SAFETY_LIB);
98
+ const qa = fs.mkdtempSync(path.join(os.tmpdir(), 'qa-cln007-'));
99
+ try {
100
+ const lockPath = path.join(qa, '.runtime', 'supervisor.lock');
101
+ // A stale lock: OLD timestamp, pid of a process that no longer exists
102
+ // (or may have been reused) — age or liveness alone must NOT free it.
103
+ const ancient = new Date(Date.now() - 90 * 24 * 3600 * 1000).toISOString();
104
+ fs.mkdirSync(path.dirname(lockPath), { recursive: true });
105
+ fs.writeFileSync(lockPath, JSON.stringify({ pid: 3999999, token: 'stale', at: ancient, command: 'node supervisor.cjs --qa', directory: qa }));
106
+ let locked = null;
107
+ try { acquireLock(lockPath, {}); } catch (error) { locked = error; }
108
+ assert.ok(locked && /LOCKED/.test(String(locked && locked.code || locked)), 'QA-SPEC-CLN-007: a 90-day-old stale lock still blocks — never auto-deleted by age');
109
+ // The lock record carries what a human needs to verify: pid, start
110
+ // time, command, directory.
111
+ const record = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
112
+ for (const field of ['pid', 'at', 'command', 'directory']) {
113
+ assert.ok(record[field] !== undefined, `QA-SPEC-CLN-007: lock record carries ${field} for human/platform-supervised recovery`);
114
+ }
115
+ // The cleanup planner never lists locks for deletion.
116
+ const run = ownedRun(qa, 'r1');
117
+ setRunStatus(run, 'PASSED');
118
+ const old = new Date(Date.now() - 30 * 24 * 3600 * 1000).toISOString();
119
+ const marker = path.join(run, '.qa-owner.json');
120
+ const state = JSON.parse(fs.readFileSync(marker, 'utf8')); state.finishedAt = old;
121
+ fs.writeFileSync(marker, JSON.stringify(state));
122
+ const plan = cleanupPlan(qa, 1);
123
+ assert.ok(!JSON.stringify(plan).includes('.lock') || !plan.entries.some(e => /lock/i.test(e.dir || '')),
124
+ 'QA-SPEC-CLN-007: cleanup planner lists no lock file — locks are outside age-based cleanup');
125
+ assert.ok(fs.existsSync(lockPath), 'QA-SPEC-CLN-007: the stale lock file is still present after planning');
126
+ console.log('QA-SPEC-CLN-007: stale lock blocks regardless of age; record fields verified; cleanup plan excludes locks');
127
+ } finally {
128
+ fs.rmSync(qa, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
129
+ }
130
+ }
131
+
132
+ console.log('t07c-cln-001-002-007-coverage-test PASS');
133
+ }
134
+
135
+ main();
@@ -0,0 +1,224 @@
1
+ // _site/_test/t07d-git-rel-coverage-test.js
2
+ //
3
+ // T07D ledger coverage for the git/release-discipline specs:
4
+ //
5
+ // GIT-002 基准远程验证 — annotated (non-v) baseline tag + QA branch must be
6
+ // verified REMOTELY via ls-remote dereference; the tag object SHA differs
7
+ // from the commit SHA, proving plain ls-remote is not enough.
8
+ // GIT-005 Push回执丢失 — when the client missed the push receipt, the
9
+ // reconciliation reads remote HEAD/parent and confirms WITHOUT a new
10
+ // commit and WITHOUT force push.
11
+ // GIT-006 CI取消失败 — the SHIPPED promote CI gate (checkCiGate) refuses
12
+ // failed/cancelled/incomplete-job runs; the sha/branch matching lives in
13
+ // the real ciStatus filter (source-anchored).
14
+ // GIT-007 单问题回退 — a controlled git revert keeps the FULL remote
15
+ // history; nothing is rewritten.
16
+ // REL-001 正式通道封锁 — only the exact x.y.z-rc.n form is a candidate;
17
+ // STABLE versions reject rc; latest has no automatic exit.
18
+ // REL-003 制品泄漏 — the shipped pack validator refuses qa/state/.env/
19
+ // credentials and REQUIRES the runtime essentials.
20
+ // REL-008 稳定版审批 — the promotion gate accepts only the exact
21
+ // READY_FOR_STABLE_APPROVAL attestation and refuses rc versions.
22
+ //
23
+ // Every assertion message starts with QA-SPEC-<CASE>.
24
+
25
+ 'use strict';
26
+
27
+ const assert = require('node:assert/strict');
28
+ const fs = require('node:fs');
29
+ const os = require('node:os');
30
+ const path = require('node:path');
31
+ const { execFileSync } = require('node:child_process');
32
+
33
+ const REPO = path.resolve(__dirname, '..', '..');
34
+
35
+ function git(dir, args) { return execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', windowsHide: true }); }
36
+ function gitOk(dir, args) { try { git(dir, args); return true; } catch { return false; } }
37
+
38
+ function fixtureRepo() {
39
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'qa-git-rel-'));
40
+ const remote = path.join(root, 'remote.git');
41
+ const work = path.join(root, 'work');
42
+ fs.mkdirSync(work, { recursive: true });
43
+ git(work, ['init', '-q', '--bare', remote]);
44
+ git(work, ['init', '-q', '-b', 'main']);
45
+ for (const [key, value] of [['user.email', 'qa-git@example.invalid'], ['user.name', 'qa-git']]) git(work, ['config', key, value]);
46
+ return { root, remote, work, cleanup: () => fs.rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }) };
47
+ }
48
+ const commit = (work, file, text, message) => {
49
+ fs.writeFileSync(path.join(work, file), text, 'utf8');
50
+ git(work, ['add', file]);
51
+ git(work, ['commit', '-q', '-m', message]);
52
+ return git(work, ['rev-parse', 'HEAD']).trim();
53
+ };
54
+
55
+ function main() {
56
+ // ---------------- GIT-002 基准远程验证 --------------------------------
57
+ {
58
+ const f = fixtureRepo();
59
+ try {
60
+ const baselineSha = commit(f.work, 'BASELINE.md', 'baseline\n', 'baseline commit');
61
+ git(f.work, ['remote', 'add', 'origin', f.remote]);
62
+ // An annotated, NON-v tag (exactly the spec's shape).
63
+ git(f.work, ['tag', '-a', 'baseline-2026Q4', '-m', 'baseline 2026Q4']);
64
+ git(f.work, ['branch', 'qa/acceptance-r9']);
65
+ git(f.work, ['push', '-q', 'origin', 'main', 'baseline-2026Q4', 'qa/acceptance-r9']);
66
+
67
+ // Remote verification — dereferenced tag and branch both must be the
68
+ // FULL baseline SHA, read from the REMOTE, not from local state.
69
+ const tagCommit = git(f.work, ['ls-remote', 'origin', 'refs/tags/baseline-2026Q4^{}']).trim().split(/\s+/)[0];
70
+ const tagObject = git(f.work, ['ls-remote', 'origin', 'refs/tags/baseline-2026Q4']).trim().split(/\s+/)[0];
71
+ const branchSha = git(f.work, ['ls-remote', 'origin', 'refs/heads/qa/acceptance-r9']).trim().split(/\s+/)[0];
72
+ assert.ok(tagCommit === baselineSha, `QA-SPEC-GIT-002: the dereferenced tag commit is the full baseline SHA (${tagCommit} vs ${baselineSha})`);
73
+ assert.notStrictEqual(tagObject, tagCommit, 'QA-SPEC-GIT-002: annotated tag object SHA differs from the commit — dereference (^{}) is REQUIRED, a plain ls-remote is not verification');
74
+ assert.ok(/^[0-9a-f]{40}$/.test(tagCommit), 'QA-SPEC-GIT-002: the verified SHA is a complete 40-hex baseline SHA');
75
+ assert.ok(branchSha === baselineSha, 'QA-SPEC-GIT-002: the QA branch points at the same complete baseline SHA remotely');
76
+ console.log('QA-SPEC-GIT-002: remote baseline verified via ls-remote dereference + branch; local command success alone is never the proof');
77
+ } finally { f.cleanup(); }
78
+ }
79
+
80
+ // ---------------- GIT-005 Push回执丢失 --------------------------------
81
+ {
82
+ const f = fixtureRepo();
83
+ try {
84
+ const first = commit(f.work, 'A.txt', 'a\n', 'first');
85
+ const second = commit(f.work, 'B.txt', 'b\n', 'second');
86
+ git(f.work, ['remote', 'add', 'origin', f.remote]);
87
+ git(f.work, ['push', '-q', 'origin', 'main']);
88
+ const localCount = git(f.work, ['rev-list', '--count', 'HEAD']).trim();
89
+
90
+ // Reconciliation after a "lost receipt": read the REMOTE HEAD and its
91
+ // parent; only then confirm. No new commit, no force push.
92
+ const remoteHead = git(f.work, ['ls-remote', 'origin', 'refs/heads/main']).trim().split(/\s+/)[0];
93
+ assert.ok(remoteHead === second, 'QA-SPEC-GIT-005: remote HEAD equals the local commit — the push did land');
94
+ const remoteParent = git(f.work, ['ls-remote', 'origin', 'refs/heads/main'])
95
+ && git(f.work, ['cat-file', '-p', remoteHead]).split('\n').find(l => l.startsWith('parent ')).split(' ')[1].trim();
96
+ assert.ok(remoteParent === first, 'QA-SPEC-GIT-005: the remote parent matches the local parent — identity proven before any action');
97
+ const afterCount = git(f.work, ['rev-list', '--count', 'HEAD']).trim();
98
+ assert.ok(afterCount === localCount, 'QA-SPEC-GIT-005: reconciliation creates NO duplicate commit');
99
+ // A force push is never needed: nothing is unpushed and nothing
100
+ // diverges, structurally (a force push would only ever be needed when
101
+ // local and remote have DIVERGED).
102
+ git(f.work, ['fetch', '-q', 'origin']);
103
+ const unpushed = git(f.work, ['rev-list', '--count', 'origin/main..HEAD']).trim();
104
+ const diverged = git(f.work, ['rev-list', '--count', 'HEAD..origin/main']).trim();
105
+ assert.ok(unpushed === '0' && diverged === '0', `QA-SPEC-GIT-005: the reconciled state has nothing unpushed (${unpushed}) and no divergence (${diverged}) — no force push can be required`);
106
+ console.log('QA-SPEC-GIT-005: lost-receipt reconciliation reads remote HEAD/parent and confirms without re-commit or force push');
107
+ } finally { f.cleanup(); }
108
+ }
109
+
110
+ // ---------------- GIT-006 CI取消失败 ----------------------------------
111
+ {
112
+ const { checkCiGate } = require(path.join(REPO, 'qa-autopilot', 'tools', 'stable-promote.cjs'));
113
+ const { REQUIRED_CI_JOBS: all } = require(path.join(REPO, 'qa-autopilot', 'tools', 'stable-next-common.cjs'));
114
+ const jobs = names => names.map(name => ({ name, conclusion: 'success' }));
115
+ assert.ok(checkCiGate({ ciStatus: 'FAIL', jobs: jobs(all), sourceSha: 'a'.repeat(40) }).ok === false,
116
+ 'QA-SPEC-GIT-006: a FAILED run is never PASS (CI_NOT_GREEN)');
117
+ assert.ok(checkCiGate({ ciStatus: 'PENDING', jobs: jobs(all), sourceSha: 'a'.repeat(40) }).ok === false,
118
+ 'QA-SPEC-GIT-006: a CANCELLED/incomplete run is never PASS');
119
+ assert.ok(checkCiGate({ ciStatus: 'PASS', jobs: jobs(all.filter(n => !n.includes('Windows'))), sourceSha: 'a'.repeat(40) }).ok === false,
120
+ 'QA-SPEC-GIT-006: missing Windows job refuses PASS (CI_JOBS_INCOMPLETE)');
121
+ assert.strictEqual(checkCiGate({ ciStatus: 'PASS', jobs: jobs(all), sourceSha: 'a'.repeat(40) }).ok, true,
122
+ 'QA-SPEC-GIT-006: only a complete green gate passes');
123
+ // SHA/branch matching is the real filter in lib/registry.cjs ciStatus —
124
+ // anchored here so the binding cannot drift silently.
125
+ const registrySource = fs.readFileSync(path.join(REPO, 'qa-autopilot', 'lib', 'registry.cjs'), 'utf8');
126
+ assert.ok(registrySource.includes("x.head_sha === sha") && registrySource.includes("x.head_branch ==="),
127
+ 'QA-SPEC-GIT-006: ciStatus matches runs by THIS head_sha AND the QA main branch — a green run of another SHA/branch never counts');
128
+ console.log('QA-SPEC-GIT-006: shipped CI gate refuses failed/cancelled/incomplete; matching is sha+branch');
129
+ }
130
+
131
+ // ---------------- GIT-007 单问题回退 ----------------------------------
132
+ {
133
+ const f = fixtureRepo();
134
+ try {
135
+ commit(f.work, 'BASE.md', 'base\n', 'baseline');
136
+ const fixSha = commit(f.work, 'check.txt', 'ok\n', 'fix: repair the check');
137
+ const regressionSha = commit(f.work, 'check.txt', 'BROKEN\n', 'regression: breaks the check');
138
+ git(f.work, ['remote', 'add', 'origin', f.remote]);
139
+ git(f.work, ['push', '-q', 'origin', 'main']);
140
+ // The regression trips the check; a CONTROLLED revert (not a rewrite).
141
+ const checkOk = () => fs.readFileSync(path.join(f.work, 'check.txt'), 'utf8').includes('ok');
142
+ assert.ok(!checkOk(), 'QA-SPEC-GIT-007: the pushed regression reproduces');
143
+ git(f.work, ['revert', '--no-edit', regressionSha]);
144
+ assert.ok(checkOk(), 'QA-SPEC-GIT-007: the controlled revert restores the behavior and the re-test passes');
145
+ git(f.work, ['push', '-q', 'origin', 'main']);
146
+ // Full remote history preserved: every original SHA is still reachable
147
+ // on the remote and the revert sits ON TOP, replacing nothing.
148
+ for (const sha of [fixSha, regressionSha]) {
149
+ assert.ok(gitOk(f.work, ['cat-file', '-e', `${sha}^{commit}`]), `QA-SPEC-GIT-007: original commit ${sha.slice(0, 8)} still exists`);
150
+ const inRemote = git(f.work, ['branch', '-r', '--contains', sha]).includes('origin/main');
151
+ assert.ok(inRemote, `QA-SPEC-GIT-007: original commit ${sha.slice(0, 8)} remains in the REMOTE history`);
152
+ }
153
+ const remoteLog = git(f.work, ['log', '--oneline', 'origin/main']);
154
+ assert.ok(/revert/i.test(remoteLog) && /regression/i.test(remoteLog), 'QA-SPEC-GIT-007: remote log keeps BOTH the regression and its revert — nothing rewritten');
155
+ console.log('QA-SPEC-GIT-007: controlled revert verified; full remote history preserved');
156
+ } finally { f.cleanup(); }
157
+ }
158
+
159
+ // ---------------- REL-001 正式通道封锁 --------------------------------
160
+ {
161
+ const { isRC } = require(path.join(REPO, 'qa-autopilot', 'lib', 'registry.cjs'));
162
+ const { STABLE_VERSION } = require(path.join(REPO, 'qa-autopilot', 'tools', 'stable-next-common.cjs'));
163
+ assert.ok(isRC('5.0.31-rc.1'), 'QA-SPEC-REL-001: the exact x.y.z-rc.n form enters the candidate channel');
164
+ for (const bad of ['v5.0.31-rc.1', 'baseline-2026Q4', '5.0.31-rc', '5.0.31-RC.1', '5.0.31-rc.1-beta', '5.0.31']) {
165
+ assert.ok(!isRC(bad), `QA-SPEC-REL-001: ${bad} is NOT a candidate rc`);
166
+ }
167
+ assert.ok(!STABLE_VERSION.test('5.0.31-rc.1') && STABLE_VERSION.test('5.0.31'),
168
+ 'QA-SPEC-REL-001: an rc can never be a stable latest — latest has no automatic exit from the rc channel');
169
+ console.log('QA-SPEC-REL-001: only the exact rc form is a candidate; latest never auto-exits');
170
+ }
171
+
172
+ // ---------------- REL-003 制品泄漏 ------------------------------------
173
+ {
174
+ const { validatePack } = require(path.join(REPO, 'qa-autopilot', 'lib', 'registry.cjs'));
175
+ const essentials = ['package.json', '_site/server.js', 'ui/index.html', 'ui/product.js', 'ui/live-client.js', 'module-runtime-manifest.json', 'vendor-manifest.json'];
176
+ assert.throws(() => validatePack([...essentials, 'qa-autopilot/tools/x.cjs']), /Forbidden package file.*qa-autopilot/,
177
+ 'QA-SPEC-REL-003: qa/ paths are refused in the pack');
178
+ assert.throws(() => validatePack([...essentials, 'state/runs/1.json']), /Forbidden package file.*state/,
179
+ 'QA-SPEC-REL-003: state/ paths are refused');
180
+ assert.throws(() => validatePack([...essentials, '.env']), /Forbidden package file.*.env/,
181
+ 'QA-SPEC-REL-003: .env is refused');
182
+ assert.throws(() => validatePack([...essentials, 'ai-profiles.json']), /Forbidden package file.*ai-profiles/,
183
+ 'QA-SPEC-REL-003: credentials-shaped files are refused');
184
+ for (const required of ['_site/server.js', 'module-runtime-manifest.json', 'ui/product.js']) {
185
+ assert.throws(() => validatePack(essentials.filter(f => f !== required)), /Required runtime missing/,
186
+ `QA-SPEC-REL-003: removing the essential ${required} is refused — the engine/plugins runtime cannot be cleaned away`);
187
+ }
188
+ assert.doesNotThrow(() => validatePack([...essentials, '_modules/knowledge-engine/src/server.js', 'plugins/project-knowledge/plugin.json']),
189
+ 'QA-SPEC-REL-003: the required engine and plugin payload passes the audit');
190
+ console.log('QA-SPEC-REL-003: leak paths refused; required runtime essentials protected');
191
+ }
192
+
193
+ // ---------------- REL-008 稳定版审批 ----------------------------------
194
+ {
195
+ const promote = require(path.join(REPO, 'qa-autopilot', 'tools', 'stable-promote.cjs'));
196
+ const base = {
197
+ repository: 'SanQianX/project-knowledge-base',
198
+ workflowRef: 'SanQianX/project-knowledge-base/.github/workflows/publish.yml@refs/heads/main',
199
+ eventName: 'workflow_dispatch',
200
+ packageName: '@sanqianx/project-knowledge',
201
+ expectedVersion: '5.0.31',
202
+ sourceSha: 'a'.repeat(40),
203
+ expectedSRI: 'sha512-' + 'A'.repeat(86) + '==',
204
+ reviewer: 'ZCode-Leader',
205
+ acceptanceAck: promote.ACCEPTANCE_ACK,
206
+ expectedCurrentLatest: '5.0.30',
207
+ };
208
+ assert.strictEqual(promote.checkPromotionInputs(base).ok, true, 'QA-SPEC-REL-008: complete, attested promotion inputs pass the gate');
209
+ assert.ok(promote.checkPromotionInputs({ ...base, expectedVersion: '5.0.31-rc.1' }).code === 'VERSION_SEMVER',
210
+ 'QA-SPEC-REL-008: an rc version is REFUSED for latest — rc is never re-tagged directly');
211
+ assert.ok(promote.checkPromotionInputs({ ...base, acceptanceAck: 'looks-good-to-me' }).code === 'ACCEPTANCE_ACK',
212
+ 'QA-SPEC-REL-008: only the exact READY_FOR_STABLE_APPROVAL attestation passes');
213
+ assert.ok(promote.checkPromotionInputs({ ...base, reviewer: '' }).code === 'REVIEWER_REQUIRED',
214
+ 'QA-SPEC-REL-008: an anonymous approval is refused');
215
+ assert.ok(promote.checkPromotionInputs({ ...base, repository: 'someone/else' }).code === 'CI_IDENTITY',
216
+ 'QA-SPEC-REL-008: only this repository\'s workflow may promote');
217
+ assert.strictEqual(promote.PROMOTION_TAG, 'latest');
218
+ console.log('QA-SPEC-REL-008: stable approval requires the exact attestation; rc cannot be re-tagged latest');
219
+ }
220
+
221
+ console.log('t07d-git-rel-coverage-test PASS');
222
+ }
223
+
224
+ main();
@@ -0,0 +1,195 @@
1
+ // _site/_test/t07e-qta-coverage-test.js
2
+ //
3
+ // T07E ledger coverage for the four remaining quota-discipline specs:
4
+ //
5
+ // QTA-001 账户识别 — the SHIPPED profile-quota parser (workbench
6
+ // profile-quota.js) maps subscription usage windows from the official
7
+ // endpoints; a PAYG balance field is NEVER read into a five-hour window
8
+ // (balance simply has no mapping), and count windows carry 'requests'
9
+ // units, never money.
10
+ // QTA-002 usage字段歧义 — replay through the REAL parser: a payload with
11
+ // ONLY usage counts yields null remaining percent (UNKNOWN — nothing
12
+ // guessed); a payload with an explicit server percentage uses it; the
13
+ // GLM percentage is documented-and-parsed as the USED percent.
14
+ // QTA-007 进程重启 — the SHIPPED supervisor reconcile(): a preserved
15
+ // checkpoint whose PUSH landed while the controller was down becomes
16
+ // PUSH_ALREADY_PRESENT (never re-pushed); a half-finished worker whose
17
+ // state is UNKNOWN goes back to PENDING for independent review — never
18
+ // blindly advanced or re-dispatched.
19
+ // QTA-008 绕过防护 — the SHIPPED worker isolation: withSanitizedEnv strips
20
+ // every ambient credential variable (ANTHROPIC_/CLAUDE_/CODEX_/…) from
21
+ // worker processes, and the supervisor contract is hash-frozen per task
22
+ // so a worker cannot widen its own control contract.
23
+
24
+ 'use strict';
25
+
26
+ const assert = require('node:assert/strict');
27
+ const fs = require('node:fs');
28
+ const os = require('node:os');
29
+ const path = require('node:path');
30
+ const { execFileSync } = require('node:child_process');
31
+
32
+ const REPO = path.resolve(__dirname, '..', '..');
33
+
34
+ function jsonResponse(body) {
35
+ return { ok: true, status: 200, json: async () => body, text: async () => JSON.stringify(body), headers: new Map() };
36
+ }
37
+
38
+ async function main() {
39
+ const { ProfileQuotaService, detectProvider } = require(path.join(REPO, 'node_modules', 'claude-ai-workbench', 'packages', 'server', 'lib', 'profile-quota.js'));
40
+
41
+ // ---------------- QTA-001 / QTA-002: the real parser ------------------
42
+ {
43
+ const now = Date.parse('2026-11-06T08:00:00.000Z');
44
+ let lastBody = null;
45
+ const fetchImpl = async () => jsonResponse(lastBody);
46
+ const service = new ProfileQuotaService({ fetch: fetchImpl, now: () => now, ttlMs: 0 });
47
+ const profile = { id: 'p1', provider: 'minimax', name: 'MiniMax', baseUrl: 'https://www.minimaxi.com/api/v1', models: { default: 'abab6.5s-chat' } };
48
+ const credential = 'test-key';
49
+
50
+ // Replay 1 (QTA-002): ONLY usage counts — no percentage anywhere.
51
+ lastBody = {
52
+ base_resp: { status_code: 0 },
53
+ balance: { amount: 42.5, currency: 'CNY' }, // stray PAYG balance field
54
+ model_remains: [{
55
+ model_name: 'general',
56
+ start_time: now - 3600_000, end_time: now + 4 * 3600_000,
57
+ current_interval_usage_count: 5, current_interval_total_count: 100,
58
+ weekly_start_time: now - 86400_000 * 3, weekly_end_time: now + 86400_000 * 4,
59
+ current_weekly_usage_count: 30, current_weekly_total_count: 500,
60
+ }],
61
+ };
62
+ const onlyCounts = await service.getQuota({ profile, credential, refresh: true });
63
+ const windows = onlyCounts.windows || [];
64
+ const interval = windows.find(w => w.kind === 'interval');
65
+ const weekly = windows.find(w => w.kind === 'weekly');
66
+ assert.ok(interval && interval.used === 5 && interval.total === 100 && interval.unit === 'requests',
67
+ 'QA-SPEC-QTA-001: subscription usage windows are read from the official count fields with requests units');
68
+ assert.ok(JSON.stringify(onlyCounts).indexOf('42.5') === -1,
69
+ 'QA-SPEC-QTA-001: the PAYG balance value never leaks into any quota window — balance is not a five-hour allowance');
70
+ assert.ok(interval.serverRemainingPercent === null,
71
+ 'QA-SPEC-QTA-002: with ONLY usage counts the remaining percent stays null (UNKNOWN) — nothing is guessed');
72
+ assert.ok(weekly && weekly.serverRemainingPercent === null,
73
+ 'QA-SPEC-QTA-002: the weekly window stays UNKNOWN too without semantic evidence');
74
+
75
+ // Replay 2 (QTA-002): explicit server-computed percentage present.
76
+ const service2 = new ProfileQuotaService({ fetch: fetchImpl, now: () => now, ttlMs: 0 });
77
+ lastBody = {
78
+ base_resp: { status_code: 0 },
79
+ model_remains: [{
80
+ model_name: 'general',
81
+ start_time: now - 3600_000, end_time: now + 4 * 3600_000,
82
+ current_interval_usage_count: 5, current_interval_total_count: 100,
83
+ current_interval_remaining_percent: 95,
84
+ weekly_start_time: now - 86400_000 * 3, weekly_end_time: now + 86400_000 * 4,
85
+ current_weekly_usage_count: 30, current_weekly_total_count: 500,
86
+ current_weekly_remaining_percent: 88,
87
+ }],
88
+ };
89
+ const withPercent = await service2.getQuota({ profile, credential, refresh: true });
90
+ const interval2 = (withPercent.windows || []).find(w => w.kind === 'interval');
91
+ const weekly2 = (withPercent.windows || []).find(w => w.kind === 'weekly');
92
+ assert.ok(interval2.serverRemainingPercent === 95 && weekly2.serverRemainingPercent === 88,
93
+ 'QA-SPEC-QTA-002: an explicit server-computed percentage takes priority and is surfaced as-is');
94
+
95
+ // GLM shape: percentage is the USED percent (documented) and stays
96
+ // UNKNOWN when absent — never guessed into a remaining value.
97
+ const glmProfile = { id: 'p2', provider: 'glm', name: 'GLM', baseUrl: 'https://open.bigmodel.cn/api/paas/v4', models: { default: 'glm-4.6' } };
98
+ const glmNoPercent = { code: 200, success: true, data: { limits: [{ type: 'TIME_LIMIT', unit: 3, number: 5, currentValue: 8, usage: 4000, remaining: 3992, nextResetTime: now + 3600_000 }] } };
99
+ lastBody = glmNoPercent;
100
+ const glmUnknown = await service2.getQuota({ profile: glmProfile, credential, refresh: true });
101
+ const toolsWindowUnknown = (glmUnknown.windows || []).find(w => w.kind === 'tools');
102
+ assert.ok(toolsWindowUnknown && toolsWindowUnknown.usedPercent === null && toolsWindowUnknown.remainingPercent === null,
103
+ 'QA-SPEC-QTA-002: GLM window without percentage stays UNKNOWN both ways');
104
+ lastBody = { code: 200, success: true, data: { limits: [{ type: 'TIME_LIMIT', unit: 3, number: 5, percentage: 1, currentValue: 8, usage: 4000, remaining: 3992, nextResetTime: now + 3600_000 }] } };
105
+ const glmPercent = await service2.getQuota({ profile: glmProfile, credential, refresh: true });
106
+ const toolsWindow = (glmPercent.windows || []).find(w => w.kind === 'tools');
107
+ assert.ok(toolsWindow.usedPercent === 1 && toolsWindow.remainingPercent === 99,
108
+ 'QA-SPEC-QTA-002: the explicit percentage is applied with its documented USED semantics (8/4000 used -> 1% used, 99% remaining), protecting the old-plan entitlement');
109
+ assert.ok(detectProvider(glmProfile).id === 'glm' && detectProvider(profile).id === 'minimax',
110
+ 'QA-SPEC-QTA-001: account/provider identification distinguishes the actual endpoints');
111
+ console.log('QA-SPEC-QTA-001/002: real parser replay — balance never becomes a window; UNKNOWN without semantic evidence; explicit percentages honored');
112
+ }
113
+
114
+ // ---------------- QTA-007: shipped reconcile --------------------------
115
+ {
116
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'qa-qta007-'));
117
+ try {
118
+ const work = path.join(root, 'work');
119
+ fs.mkdirSync(work, { recursive: true });
120
+ const git = args => execFileSync('git', ['-C', work, ...args], { encoding: 'utf8', windowsHide: true });
121
+ git(['init', '-q', '-b', 'main']);
122
+ git(['config', 'user.email', 'qta@example.invalid']); git(['config', 'user.name', 'qta']);
123
+ fs.writeFileSync(path.join(work, 'A.md'), 'a\n');
124
+ git(['add', 'A.md']); git(['commit', '-q', '-m', 'one']);
125
+ const head = git(['rev-parse', 'HEAD']).trim();
126
+ const remote = path.join(root, 'remote.git');
127
+ git(['init', '-q', '--bare', remote]);
128
+ git(['remote', 'add', 'origin', remote]);
129
+ git(['push', '-q', 'origin', 'main']); // the PUSH landed while the controller was "down"
130
+
131
+ const stateDir = path.join(root, 'state');
132
+ fs.mkdirSync(stateDir, { recursive: true });
133
+ fs.writeFileSync(path.join(stateDir, 'queue.json'), JSON.stringify([]));
134
+ // The supervisor reads its fixed paths from QA_OVERNIGHT_STATE_DIR —
135
+ // redirect BEFORE require so the module constants point at the fixture.
136
+ process.env.QA_OVERNIGHT_STATE_DIR = stateDir;
137
+ const { reconcile } = require(path.join(REPO, 'qa-autopilot', 'tools', 'overnight-supervisor.cjs'));
138
+ const cfg = { repoRoot: work, mainBranch: 'main', tools: {} };
139
+ const state = {
140
+ order: ['t1', 't2'],
141
+ tasks: {
142
+ t1: { id: 't1', status: 'PUSHED', commitSha: head }, // receipt unknown, remote HAS it
143
+ t2: { id: 't2', status: 'AGENT_RUNNING', commitSha: null }, // worker state unknown at restart
144
+ },
145
+ };
146
+ const notes = reconcile(cfg, state);
147
+ const n1 = notes.find(n => n.id === 't1');
148
+ const n2 = notes.find(n => n.id === 't2');
149
+ assert.ok(n1 && n1.action === 'PUSH_ALREADY_PRESENT',
150
+ `QA-SPEC-QTA-007: the already-pushed task is reconciled as PUSH_ALREADY_PRESENT (never re-pushed): ${JSON.stringify(n1)}`);
151
+ assert.ok(state.tasks.t1.status === 'CI_PENDING', 'QA-SPEC-QTA-007: the reconciled pushed task moves to CI_PENDING, not back to dispatch');
152
+ assert.ok(n2 && n2.action === 'HALF_FINISHED_BACK_TO_PENDING',
153
+ `QA-SPEC-QTA-007: the unknown-state worker goes back to PENDING for independent review: ${JSON.stringify(n2)}`);
154
+ assert.ok(state.tasks.t2.status === 'PENDING' && state.tasks.t2.halfFinished === true,
155
+ 'QA-SPEC-QTA-007: the half-finished task is NOT advanced and NOT re-dispatched blindly');
156
+ console.log('QA-SPEC-QTA-007: shipped reconcile verifies remote state; unknown workers reconcile, never resend');
157
+ } finally { fs.rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }); }
158
+ }
159
+
160
+ // ---------------- QTA-008: shipped worker isolation -------------------
161
+ {
162
+ const { withSanitizedEnv, AMBIENT_PREFIXES } = require(path.join(REPO, '_site', '_test', 'helpers', 'parallel-memory-capture-r3-cap-shell'));
163
+ assert.ok(AMBIENT_PREFIXES.includes('ANTHROPIC_') && AMBIENT_PREFIXES.includes('CLAUDE_') && AMBIENT_PREFIXES.includes('CODEX_'),
164
+ 'QA-SPEC-QTA-008: ambient credential prefixes are pinned in the shipped worker isolation');
165
+ // The probes are set BY THIS TEST (an offline CI lane must never depend
166
+ // on the calling shell carrying real credentials): synthetic probe values
167
+ // stand in for ambient secrets, and the isolation must strip them.
168
+ if (process.env.ANTHROPIC_PROBE_SECRET === undefined && process.env.CLAUDE_PROBE_TOKEN === undefined) {
169
+ process.env.ANTHROPIC_PROBE_SECRET = 't07e-synthetic-probe-secret';
170
+ process.env.CLAUDE_PROBE_TOKEN = 't07e-synthetic-probe-token';
171
+ }
172
+ const probeClaude = process.env.CLAUDE_PROBE_TOKEN;
173
+ const probeAnthropic = process.env.ANTHROPIC_PROBE_SECRET;
174
+ assert.ok(probeClaude !== undefined && probeAnthropic !== undefined, 'QA-SPEC-QTA-008: probe setup — ambient credential probes present in the parent env');
175
+ let seenInside = null;
176
+ withSanitizedEnv(() => {
177
+ seenInside = {
178
+ anthropic: process.env.ANTHROPIC_PROBE_SECRET,
179
+ claude: process.env.CLAUDE_PROBE_TOKEN,
180
+ };
181
+ });
182
+ assert.ok(seenInside.anthropic === undefined && seenInside.claude === undefined,
183
+ 'QA-SPEC-QTA-008: inside the sanitized worker env the ambient credentials are GONE — a worker cannot read the real subscription credentials');
184
+ // The control contract is hash-frozen per task by the shipped
185
+ // makeContract (anchored): a worker cannot widen its own contract.
186
+ const supervisorSource = fs.readFileSync(path.join(REPO, 'qa-autopilot', 'tools', 'overnight-supervisor.cjs'), 'utf8');
187
+ assert.ok(/function makeContract/.test(supervisorSource) && /contracts', task\.id \+ '\.json'/.test(supervisorSource),
188
+ 'QA-SPEC-QTA-008: the supervisor freezes each task contract into a per-task file — contract changes are detectable, not silently widened');
189
+ console.log('QA-SPEC-QTA-008: worker env isolation strips credentials; control contract is frozen per task');
190
+ }
191
+
192
+ console.log('t07e-qta-coverage-test PASS');
193
+ }
194
+
195
+ main().catch(error => { console.error(String(error && error.stack || error)); process.exit(1); });