bailinghub 0.9.0 → 0.9.2

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 (139) hide show
  1. package/.dockerignore +6 -0
  2. package/.npmignore +6 -0
  3. package/CONTRIBUTING.md +4 -0
  4. package/GOVERNANCE.md +9 -0
  5. package/README.en.md +7 -6
  6. package/README.md +7 -6
  7. package/SECURITY.md +8 -2
  8. package/THIRD_PARTY_NOTICES.md +17 -17
  9. package/docker-compose.images.yml +2 -2
  10. package/docs/CHANGELOG.en.md +22 -1
  11. package/docs/CHANGELOG.md +22 -1
  12. package/docs/COMPATIBILITY.en.md +4 -0
  13. package/docs/CORE_RELIABILITY.en.md +59 -0
  14. package/docs/CORE_RELIABILITY.md +59 -0
  15. package/docs/DEPLOYMENT_DIAGNOSTICS.en.md +78 -0
  16. package/docs/DEPLOYMENT_DIAGNOSTICS.md +78 -0
  17. package/docs/IMPLEMENTATION_STATUS.en.md +81 -0
  18. package/docs/IMPLEMENTATION_STATUS.md +81 -0
  19. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  20. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  21. package/docs/KERNEL_HOST_API.en.md +20 -0
  22. package/docs/KERNEL_HOST_API.md +20 -0
  23. package/docs/MODEL_BILLING.en.md +4 -0
  24. package/docs/MODEL_BILLING.md +4 -0
  25. package/docs/MODEL_PROCESS_RECOVERY.en.md +32 -0
  26. package/docs/MODEL_PROCESS_RECOVERY.md +37 -0
  27. package/docs/README.en.md +8 -0
  28. package/docs/README.md +8 -0
  29. package/docs/RELEASE_NOTES_NEXT.en.md +3 -3
  30. package/docs/RELEASE_NOTES_NEXT.md +3 -3
  31. package/docs/RELEASE_NOTES_v0.9.1.en.md +38 -0
  32. package/docs/RELEASE_NOTES_v0.9.1.md +38 -0
  33. package/docs/RELEASE_NOTES_v0.9.2.en.md +45 -0
  34. package/docs/RELEASE_NOTES_v0.9.2.md +45 -0
  35. package/docs/UPGRADE_v0.9.1.en.md +39 -0
  36. package/docs/UPGRADE_v0.9.1.md +39 -0
  37. package/docs/UPGRADE_v0.9.2.en.md +62 -0
  38. package/docs/UPGRADE_v0.9.2.md +62 -0
  39. package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +4 -0
  40. package/package.json +10 -5
  41. package/scripts/check-doc-links.mjs +4 -0
  42. package/scripts/check-image-tags.sh +1 -1
  43. package/scripts/check-release-consistency.test.mjs +2 -2
  44. package/scripts/dependency-audit.mjs +134 -0
  45. package/scripts/dependency-audit.test.mjs +125 -0
  46. package/scripts/doctor-deployment.test.ts +419 -0
  47. package/scripts/doctor-deployment.ts +357 -0
  48. package/scripts/doctor.ts +8 -1
  49. package/scripts/install-secrets.test.mjs +185 -0
  50. package/scripts/install.sh +10 -6
  51. package/scripts/osps-results.py +114 -0
  52. package/scripts/publish-images.sh +1 -1
  53. package/scripts/release-audit.mjs +5 -0
  54. package/scripts/verify-github-repo.mjs +5 -0
  55. package/security/dependency-audit-exceptions.json +192 -0
  56. package/sql/065_usage_reconciliation_scan.sql +4 -0
  57. package/sql/066_approval_continuations.sql +15 -0
  58. package/sql/README.md +9 -0
  59. package/src/app/approval-continuations.mysql.test.ts +138 -0
  60. package/src/app/approval-continuations.test.ts +325 -0
  61. package/src/app/approval-continuations.ts +107 -0
  62. package/src/app/http-server.ts +3 -0
  63. package/src/app/kernel-model-process-crash.mysql.test.ts +377 -0
  64. package/src/app/kernel-usage-lifecycle.mysql.test.ts +325 -0
  65. package/src/app/kernel.ts +23 -0
  66. package/src/app/runtime-evidence-maintenance.test.ts +55 -0
  67. package/src/app/runtime-lifecycle-default.ts +7 -0
  68. package/src/app/runtime-lifecycle.ts +39 -0
  69. package/src/core/contracts/approval-continuation.ts +43 -0
  70. package/src/core/contracts/types.ts +2 -0
  71. package/src/core/state/approval-continuation.ts +22 -0
  72. package/src/core/state/state-codec.ts +1 -0
  73. package/src/core/state/state-contracts.ts +3 -0
  74. package/src/infrastructure/config/config-approval-ledger.ts +75 -0
  75. package/src/infrastructure/config/configstore.ts +2 -2
  76. package/src/infrastructure/state/state-jsonl.ts +41 -11
  77. package/src/infrastructure/state/state-mysql.ts +27 -0
  78. package/src/modules/usage/background-work.test.ts +144 -0
  79. package/src/modules/usage/background-work.ts +50 -0
  80. package/src/modules/usage/billing-reconciliation.mysql.test.ts +163 -0
  81. package/src/modules/usage/billing-reconciliation.test.ts +71 -0
  82. package/src/modules/usage/billing-repository.ts +60 -15
  83. package/src/modules/usage/maintenance.test.ts +62 -0
  84. package/src/modules/usage/maintenance.ts +31 -0
  85. package/src/modules/usage/model-gateway.ts +11 -3
  86. package/src/modules/usage/model-tool-gateway.mysql.test.ts +1 -1
  87. package/src/modules/usage/pricing.ts +3 -2
  88. package/src/modules/usage/repository.ts +2 -0
  89. package/src/modules/usage/test-harness.ts +2 -1
  90. package/src/routes/admin-default.ts +2 -2
  91. package/src/routes/admin-runtime-default.ts +2 -2
  92. package/src/routes/admin-runtime.test.ts +1 -1
  93. package/src/routes/admin-runtime.ts +25 -18
  94. package/src/routes/admin.ts +1 -1
  95. package/src/routes/approvals-default.ts +2 -2
  96. package/src/routes/approvals.ts +30 -33
  97. package/src/routes/critical-routes.test.ts +16 -3
  98. package/src/test-support/approval-continuation-crash-child.ts +24 -0
  99. package/src/test-support/model-process-crash-child.ts +78 -0
  100. package/web/console/assets/{Accounts-DnddhY6t.js → Accounts-DKhw_QLr.js} +1 -1
  101. package/web/console/assets/{AgentClients-VInbD7JS.js → AgentClients-CM4_5HaA.js} +1 -1
  102. package/web/console/assets/{AgentTasks-B-1XklBg.js → AgentTasks-CkQgZTU5.js} +1 -1
  103. package/web/console/assets/{Approvals-34qUPHf0.js → Approvals-B9O9TkbO.js} +1 -1
  104. package/web/console/assets/{Audit-BbVgkSm2.js → Audit-2vDC1SPu.js} +1 -1
  105. package/web/console/assets/{BrandLockup-DgscF28e.js → BrandLockup-BgASiRSE.js} +1 -1
  106. package/web/console/assets/{Channels-Bp-yuk8d.js → Channels-A-GvkNBt.js} +1 -1
  107. package/web/console/assets/{ChatEntries-C9Ft60TS.js → ChatEntries-BLxymI67.js} +1 -1
  108. package/web/console/assets/{Clients-NPldD-DD.js → Clients-DeNlmvS6.js} +1 -1
  109. package/web/console/assets/{Cost-DZcuB-EB.js → Cost-CBq_L4Kz.js} +1 -1
  110. package/web/console/assets/{Credentials-RTT7N6zl.js → Credentials-DmtbctNj.js} +1 -1
  111. package/web/console/assets/{Diagnostics-_LeK8cce.js → Diagnostics-BbcRDiA-.js} +1 -1
  112. package/web/console/assets/{Executors-Bi7H8rIm.js → Executors-gGgmQrDt.js} +1 -1
  113. package/web/console/assets/{HelpTip-BfyWrxCE.js → HelpTip-Dtdt2tKR.js} +1 -1
  114. package/web/console/assets/{Kb-BHamz8NP.js → Kb-lgY6OXUz.js} +2 -2
  115. package/web/console/assets/{Login-C1rJR-6w.js → Login-DA6BASZd.js} +1 -1
  116. package/web/console/assets/{Projects-BRA4a48v.js → Projects-DEbmB_sT.js} +1 -1
  117. package/web/console/assets/{Routes-CTC7U-fQ.js → Routes-qS6LLoyS.js} +1 -1
  118. package/web/console/assets/{Runs-B_fa_BlD.js → Runs-DG-VLRSc.js} +1 -1
  119. package/web/console/assets/{Setup-C1_d0mFy.js → Setup-DEpVF5uw.js} +1 -1
  120. package/web/console/assets/{Shell-CHEV6RGC.js → Shell-DgoPgK1E.js} +1 -1
  121. package/web/console/assets/{StorageBuckets-DlG3ojhA.js → StorageBuckets-DJtNN769.js} +1 -1
  122. package/web/console/assets/{SystemSettings-DYo2gg6d.js → SystemSettings-0DEUgeTR.js} +1 -1
  123. package/web/console/assets/{SystemStatus-DKCoUZlq.js → SystemStatus-CR1phiPE.js} +1 -1
  124. package/web/console/assets/{Targets-CdkG6BPR.js → Targets-D65l-IMB.js} +1 -1
  125. package/web/console/assets/{Tools-DVpCt0ox.js → Tools-DqtrINrN.js} +1 -1
  126. package/web/console/assets/{Usage-DWCpLugC.js → Usage-B5njXNjx.js} +1 -1
  127. package/web/console/assets/{UsageAccess-B_Xq7ARW.js → UsageAccess-ChnB4pjb.js} +1 -1
  128. package/web/console/assets/{UsageHelp-t5ZG_f-e.js → UsageHelp-BBKIvbQ5.js} +1 -1
  129. package/web/console/assets/{index-C6W4LWVV.js → index-65JiiUr4.js} +1 -1
  130. package/web/console/assets/{index-H1kfa0Mj.js → index-sLKrJd_p.js} +2 -2
  131. package/web/console/assets/{request-DLsP1_ot.js → request-BpaimqEb.js} +1 -1
  132. package/web/console/assets/{schema-BLOHvAJQ.js → schema-D0Z4kFCZ.js} +1 -1
  133. package/web/console/assets/{util-CGVh2Jvr.js → util-DZYfJ5Zo.js} +1 -1
  134. package/web/console/assets/{vendor-element-BD089KxE.js → vendor-element-8cVcdt5T.js} +1 -1
  135. package/web/console/assets/{vendor-mammoth-Bv-CZhmH.js → vendor-mammoth-CnDA23N0.js} +1 -1
  136. package/web/console/assets/vendor-vue-Co7x2FW6.js +29 -0
  137. package/web/console/index.html +3 -3
  138. package/web-admin/package-lock.json +83 -85
  139. package/web/console/assets/vendor-vue-B2uhHUfE.js +0 -29
@@ -0,0 +1,134 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, readdirSync, lstatSync } from 'node:fs';
3
+ import { resolve, relative, join } from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { spawnSync } from 'node:child_process';
6
+
7
+ const affectedNames = ['mammoth', 'argparse', 'sprintf-js'];
8
+ const approvedAdvisory = 'https://github.com/advisories/GHSA-hp3w-g68c-fv3c';
9
+ const usagePattern = /\b(?:mammoth|argparse|sprintf-js)\b/i;
10
+ const levels = ['info', 'low', 'moderate', 'high', 'critical'];
11
+ const json = path => JSON.parse(readFileSync(path, 'utf8'));
12
+ const hash = source => createHash('sha256').update(source).digest('hex');
13
+ const stable = value => JSON.stringify(value, (_key, item) => item && typeof item === 'object' && !Array.isArray(item)
14
+ ? Object.fromEntries(Object.keys(item).sort().map(key => [key, item[key]])) : item);
15
+
16
+ function reviewedRowsAreExact(rows) {
17
+ if (!rows || Array.isArray(rows) || typeof rows !== 'object' ||
18
+ stable(Object.keys(rows).sort()) !== stable([...affectedNames].sort())) return false;
19
+ const chain = { mammoth: ['argparse'], argparse: ['sprintf-js'] };
20
+ const effects = { mammoth: [], argparse: ['mammoth'], 'sprintf-js': ['argparse'] };
21
+ for (const name of affectedNames) {
22
+ const row = rows[name];
23
+ if (!row || row.name !== name || row.severity !== 'moderate' ||
24
+ stable(row.nodes) !== stable([`node_modules/${name}`]) ||
25
+ stable(row.effects) !== stable(effects[name])) return false;
26
+ if (name !== 'sprintf-js') {
27
+ if (stable(row.via) !== stable(chain[name])) return false;
28
+ } else {
29
+ if (!Array.isArray(row.via) || row.via.length !== 1) return false;
30
+ const advisory = row.via[0];
31
+ if (!advisory || typeof advisory !== 'object' || Array.isArray(advisory) ||
32
+ advisory.name !== name || advisory.dependency !== name ||
33
+ advisory.severity !== 'moderate' || advisory.url !== approvedAdvisory) return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
38
+
39
+ export function dependencyState(lock) {
40
+ const versions = {}, references = [];
41
+ for (const [path, entry] of Object.entries(lock.packages ?? {})) {
42
+ if (affectedNames.some(name => path === `node_modules/${name}` || path.endsWith(`/node_modules/${name}`))) versions[path] = entry.version;
43
+ for (const kind of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
44
+ for (const [name, range] of Object.entries(entry[kind] ?? {})) {
45
+ if (affectedNames.includes(name)) references.push(`${path || '<root>'}|${kind}|${name}|${range}`);
46
+ }
47
+ }
48
+ }
49
+ return { versions, references: references.sort() };
50
+ }
51
+
52
+ export function collectUsage(root, scope) {
53
+ const inventory = {};
54
+ const directories = scope === 'core' ? ['src', 'scripts', '.github'] : ['web-admin/src', 'web-admin/scripts'];
55
+ const excluded = new Set(['scripts/dependency-audit.mjs', 'scripts/dependency-audit.test.mjs']);
56
+ function visit(path) {
57
+ const local = relative(root, path).replaceAll('\\', '/');
58
+ if (excluded.has(local)) return;
59
+ const stat = lstatSync(path);
60
+ if (stat.isSymbolicLink()) throw new Error(`Source symlink requires review: ${local}`);
61
+ if (stat.isDirectory()) {
62
+ for (const entry of readdirSync(path).sort()) visit(join(path, entry));
63
+ } else if (stat.isFile() && /\.(?:[cm]?js|[cm]?ts|jsx|tsx|vue|html|ya?ml|json|sh)$/.test(path)) {
64
+ const source = readFileSync(path);
65
+ if (usagePattern.test(source.toString('utf8'))) inventory[local] = hash(source);
66
+ }
67
+ }
68
+ for (const directory of directories) if (existsSync(join(root, directory))) visit(join(root, directory));
69
+ const manifestPath = scope === 'core' ? 'package.json' : 'web-admin/package.json';
70
+ const scripts = json(join(root, manifestPath)).scripts ?? {};
71
+ for (const [name, command] of Object.entries(scripts)) {
72
+ if (usagePattern.test(String(command))) inventory[`${manifestPath}#scripts.${name}`] = hash(String(command));
73
+ }
74
+ return inventory;
75
+ }
76
+
77
+ export function evaluateScope({ scope, audit, lock, usage, policy, now = new Date() }) {
78
+ const reasons = [], counts = Object.fromEntries(levels.map(level => [level, 0]));
79
+ const exception = policy.scopes?.[scope];
80
+ const from = Date.parse(policy.approvedFrom), until = Date.parse(policy.expiresAt), time = +now;
81
+ if (policy.version !== 1 || policy.owner !== 'Jingchuan Nie' || policy.advisory !== approvedAdvisory) reasons.push('Unknown exception policy');
82
+ if (![from, until, time].every(Number.isFinite) || until <= from || until - from > 30 * 86400000) reasons.push('Invalid exception period');
83
+ else if (time < from || time >= until) reasons.push('Exception is not active or has expired');
84
+ if (!exception) reasons.push(`Unknown scope: ${scope}`);
85
+ else if (!reviewedRowsAreExact(exception.knownAuditRows)) reasons.push('Exception policy must contain only the reviewed Mammoth/argparse/sprintf-js chain and advisory');
86
+ const rows = audit?.vulnerabilities;
87
+ if (audit?.auditReportVersion !== 2 || audit?.error || !rows || Array.isArray(rows) || typeof rows !== 'object') {
88
+ reasons.push('Invalid or failed npm audit response');
89
+ return { scope, pass: false, rawCounts: null, exceptedRows: 0, reasons };
90
+ }
91
+ let exceptedRows = 0;
92
+ for (const [name, row] of Object.entries(rows)) {
93
+ if (levels.includes(row.severity)) counts[row.severity]++;
94
+ else reasons.push(`Unknown vulnerability severity: ${name}`);
95
+ if (!exception?.knownAuditRows?.[name] || stable(row) !== stable(exception.knownAuditRows[name])) reasons.push(`Unreviewed vulnerability or changed advisory/dependency path: ${name}`);
96
+ else exceptedRows++;
97
+ }
98
+ counts.total = Object.keys(rows).length;
99
+ if (stable(counts) !== stable(audit.metadata?.vulnerabilities)) reasons.push('Audit counts do not match vulnerability rows');
100
+ if (exception) {
101
+ const state = dependencyState(lock);
102
+ if (stable(state.versions) !== stable(exception.packageVersions)) reasons.push('Reviewed dependency versions or installed locations changed');
103
+ if (stable(state.references) !== stable(exception.dependencyReferences)) reasons.push('New or changed dependency consumer/path requires review');
104
+ if (stable(usage) !== stable(exception.reviewedUsageFiles)) reasons.push('New/changed source or CLI usage requires review');
105
+ }
106
+ return { scope, pass: reasons.length === 0, rawCounts: counts, exceptedRows, unexceptedRows: counts.total - exceptedRows, exceptionExpiresAt: policy.expiresAt, reasons };
107
+ }
108
+
109
+ export function runScope(root, scope, policy) {
110
+ const directory = scope === 'core' ? root : join(root, 'web-admin');
111
+ const run = spawnSync('npm', ['audit', '--json'], { cwd: directory, encoding: 'utf8', timeout: 120000, maxBuffer: 8 * 1024 * 1024 });
112
+ if (run.error || run.signal || ![0, 1].includes(run.status)) throw new Error(`npm audit failed in ${scope}; exit=${run.status}`);
113
+ return evaluateScope({ scope, audit: JSON.parse(run.stdout), lock: json(join(directory, 'package-lock.json')), usage: collectUsage(root, scope), policy });
114
+ }
115
+
116
+ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
117
+ try {
118
+ const options = { root: process.cwd(), scope: 'all' };
119
+ for (let index = 2; index < process.argv.length; index += 2) {
120
+ const flag = process.argv[index], value = process.argv[index + 1];
121
+ if (!['--root', '--scope', '--policy'].includes(flag) || !value) throw new Error('Usage: dependency-audit.mjs [--root PATH] [--scope core|web-admin|all] [--policy PATH]');
122
+ options[flag.slice(2)] = value;
123
+ }
124
+ if (!['core', 'web-admin', 'all'].includes(options.scope)) throw new Error('Unknown scope');
125
+ const root = resolve(options.root), policy = json(options.policy ?? join(root, 'security/dependency-audit-exceptions.json'));
126
+ const scopes = options.scope === 'all' ? ['core', 'web-admin'] : [options.scope];
127
+ const results = scopes.map(scope => runScope(root, scope, policy));
128
+ console.log(JSON.stringify({ results, note: 'Raw findings remain open; an exact temporary exception is not a vulnerability fix.' }, null, 2));
129
+ process.exitCode = results.every(result => result.pass) ? 0 : 1;
130
+ } catch (error) {
131
+ console.error(`Dependency audit blocked: ${error.message}`);
132
+ process.exitCode = 1;
133
+ }
134
+ }
@@ -0,0 +1,125 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { readFileSync, mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { tmpdir } from 'node:os';
6
+ import { evaluateScope, collectUsage } from './dependency-audit.mjs';
7
+
8
+ const load = name => JSON.parse(readFileSync(new URL(name, import.meta.url), 'utf8'));
9
+ const policy = load('../security/dependency-audit-exceptions.json');
10
+ const now = new Date('2026-10-10T03:00:00Z');
11
+ function fixture(scope = 'core') {
12
+ const audit = { auditReportVersion: 2, vulnerabilities: structuredClone(policy.scopes[scope].knownAuditRows), metadata: { vulnerabilities: { info: 0, low: 0, moderate: 3, high: 0, critical: 0, total: 3 } } };
13
+ const lock = load(scope === 'core' ? '../package-lock.json' : '../web-admin/package-lock.json');
14
+ return { scope, audit, lock, usage: structuredClone(policy.scopes[scope].reviewedUsageFiles), policy: structuredClone(policy), now };
15
+ }
16
+ for (const scope of ['core', 'web-admin']) {
17
+ test(`${scope}: reviewed advisory passes while preserving all three moderate findings`, () => {
18
+ const result = evaluateScope(fixture(scope));
19
+ assert.equal(result.pass, true);
20
+ assert.equal(result.rawCounts.moderate, 3);
21
+ assert.equal(result.rawCounts.total, 3);
22
+ assert.equal(result.exceptedRows, 3);
23
+ assert.equal(result.unexceptedRows, 0);
24
+ });
25
+ }
26
+ test('exception expires at the exact boundary', () => {
27
+ const input = fixture(); input.now = new Date(policy.expiresAt);
28
+ assert.equal(evaluateScope(input).pass, false);
29
+ });
30
+ test('exception cannot begin before the approval period or exceed 30 days', () => {
31
+ const input = fixture(); input.now = new Date('2026-10-09T23:59:59Z');
32
+ assert.equal(evaluateScope(input).pass, false);
33
+ input.now = now; input.policy.expiresAt = '2026-11-10T00:00:00Z';
34
+ assert.equal(evaluateScope(input).pass, false);
35
+ });
36
+ test('a new moderate finding is blocked rather than globally ignored', () => {
37
+ const input = fixture();
38
+ input.audit.vulnerabilities.newPackage = { name: 'newPackage', severity: 'moderate', via: [{ url: 'https://github.com/advisories/GHSA-new' }], nodes: ['node_modules/newPackage'] };
39
+ input.audit.metadata.vulnerabilities.moderate++;
40
+ input.audit.metadata.vulnerabilities.total++;
41
+ const result = evaluateScope(input);
42
+ assert.equal(result.pass, false); assert.equal(result.rawCounts.moderate, 4); assert.equal(result.unexceptedRows, 1);
43
+ });
44
+ test('an additional advisory on the accepted package is blocked', () => {
45
+ const input = fixture(); input.audit.vulnerabilities['sprintf-js'].via.push({ url: 'https://github.com/advisories/GHSA-new', severity: 'high' });
46
+ assert.equal(evaluateScope(input).pass, false);
47
+ });
48
+ test('adding an unrelated advisory to both policy and audit cannot broaden the exception', () => {
49
+ const input = fixture();
50
+ const row = { name: 'anotherPackage', severity: 'moderate', via: [{ url: 'https://github.com/advisories/GHSA-new', severity: 'moderate' }], nodes: ['node_modules/anotherPackage'] };
51
+ input.policy.scopes.core.knownAuditRows.anotherPackage = structuredClone(row);
52
+ input.audit.vulnerabilities.anotherPackage = row;
53
+ input.audit.metadata.vulnerabilities.moderate++;
54
+ input.audit.metadata.vulnerabilities.total++;
55
+ assert.equal(evaluateScope(input).pass, false);
56
+ });
57
+ test('changing or appending an advisory in both policy and audit is blocked', () => {
58
+ const input = fixture();
59
+ for (const rows of [input.policy.scopes.core.knownAuditRows, input.audit.vulnerabilities]) {
60
+ rows['sprintf-js'].via[0].url = 'https://github.com/advisories/GHSA-new';
61
+ }
62
+ assert.equal(evaluateScope(input).pass, false);
63
+ const next = fixture();
64
+ for (const rows of [next.policy.scopes.core.knownAuditRows, next.audit.vulnerabilities]) {
65
+ rows['sprintf-js'].via.push({ url: 'https://github.com/advisories/GHSA-new', severity: 'moderate' });
66
+ }
67
+ assert.equal(evaluateScope(next).pass, false);
68
+ });
69
+ test('rewriting the reviewed dependency chain in both policy and audit is blocked', () => {
70
+ const input = fixture();
71
+ for (const rows of [input.policy.scopes.core.knownAuditRows, input.audit.vulnerabilities]) {
72
+ rows.argparse.via = ['anotherPackage'];
73
+ rows['sprintf-js'].effects = ['anotherPackage'];
74
+ }
75
+ assert.equal(evaluateScope(input).pass, false);
76
+ });
77
+ test('removing a reviewed policy row cannot redefine the approved exception', () => {
78
+ const input = fixture();
79
+ delete input.policy.scopes.core.knownAuditRows.argparse;
80
+ delete input.audit.vulnerabilities.argparse;
81
+ input.audit.metadata.vulnerabilities.moderate--;
82
+ input.audit.metadata.vulnerabilities.total--;
83
+ assert.equal(evaluateScope(input).pass, false);
84
+ });
85
+ test('a changed audit node or suggested fix cannot silently broaden the exception', () => {
86
+ const input = fixture(); input.audit.vulnerabilities['sprintf-js'].nodes.push('node_modules/new/node_modules/sprintf-js');
87
+ assert.equal(evaluateScope(input).pass, false);
88
+ const next = fixture(); next.audit.vulnerabilities['sprintf-js'].fixAvailable = true;
89
+ assert.equal(evaluateScope(next).pass, false);
90
+ });
91
+ test('a changed dependency version or additional installed copy is blocked', () => {
92
+ const input = fixture(); input.lock.packages['node_modules/mammoth'].version = '1.13.0';
93
+ assert.equal(evaluateScope(input).pass, false);
94
+ const next = fixture(); next.lock.packages['node_modules/new/node_modules/sprintf-js'] = { version: '1.0.3' };
95
+ assert.equal(evaluateScope(next).pass, false);
96
+ });
97
+ test('a new package consuming the same vulnerable copy is blocked', () => {
98
+ const input = fixture(); input.lock.packages['node_modules/new-consumer'] = { version: '1.0.0', dependencies: { 'sprintf-js': '~1.0.2' } };
99
+ assert.equal(evaluateScope(input).pass, false);
100
+ });
101
+ test('new CLI usage and modified reviewed library usage are blocked', () => {
102
+ const input = fixture(); input.usage['src/new-cli.ts'] = 'unreviewed';
103
+ assert.equal(evaluateScope(input).pass, false);
104
+ const next = fixture(); next.usage['src/adapters/llm/file.ts'] = 'modified';
105
+ assert.equal(evaluateScope(next).pass, false);
106
+ });
107
+ test('filesystem inventory detects a new source CLI and package script CLI', () => {
108
+ const root = mkdtempSync(join(tmpdir(), 'dependency-audit-usage-'));
109
+ try {
110
+ mkdirSync(join(root, 'src'));
111
+ writeFileSync(join(root, 'src/new-cli.ts'), "spawn('mammoth', ['input.docx']);\n");
112
+ writeFileSync(join(root, 'package.json'), JSON.stringify({ scripts: { convert: 'mammoth input.docx' } }));
113
+ const usage = collectUsage(root, 'core');
114
+ assert.ok(usage['src/new-cli.ts']);
115
+ assert.ok(usage['package.json#scripts.convert']);
116
+ const input = fixture(); input.usage = usage;
117
+ assert.equal(evaluateScope(input).pass, false);
118
+ } finally { rmSync(root, { recursive: true, force: true }); }
119
+ });
120
+ test('failed audit payload and misleading aggregate counts fail closed', () => {
121
+ const input = fixture(); input.audit.error = { code: 'EACCESS' };
122
+ assert.equal(evaluateScope(input).pass, false);
123
+ const next = fixture(); next.audit.metadata.vulnerabilities.total = 0;
124
+ assert.equal(evaluateScope(next).pass, false);
125
+ });