@namewta/skills-hub 0.1.49 → 0.1.52
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.
- package/README.md +4 -1
- package/THIRD_PARTY_NOTICES.md +19 -7
- package/cli.mjs +2 -2
- package/install.mjs +11 -4
- package/package.json +1 -1
- package/scripts/persistence/home.md +1 -1
- package/skills/dev/dev-build/SKILL.md +2 -0
- package/skills/dev/dev-build/references/implement-request.md +7 -2
- package/skills/dev/dev-formal-verify/SKILL.md +2 -1
- package/skills/dev/dev-formal-verify/references/create-check.md +3 -1
- package/skills/dev/dev-formal-verify/references/example.md +1 -1
- package/skills/dev/dev-formal-verify/references/tool-choice.md +1 -1
- package/skills/dev/dev-help/references/capabilities.md +6 -6
- package/skills/dev/dev-help/references/guide-verification.md +7 -1
- package/skills/dev/dev-help/references/help-method.md +7 -1
- package/skills/dev/dev-issue/SKILL.md +1 -0
- package/skills/dev/dev-issue/references/github-operations.md +8 -0
- package/skills/dev/dev-plan/references/plan-template.md +1 -0
- package/skills/dev/dev-plan/references/vertical-slicing.md +2 -0
- package/skills/dev/dev-pr/references/pull-request-evidence.md +2 -0
- package/skills/dev/dev-review/references/host-parity.md +12 -0
- package/skills/dev/dev-review/references/review-baseline.md +2 -0
- package/skills/dev/dev-setup/references/formal-options.md +1 -1
- package/skills/dev/dev-statechart/SKILL.md +17 -19
- package/skills/dev/dev-statechart/agents/openai.yaml +3 -3
- package/skills/dev/dev-statechart/assets/theme.css +135 -0
- package/skills/dev/dev-statechart/references/lean-proof.md +47 -0
- package/skills/dev/dev-statechart/references/render.md +15 -83
- package/skills/dev/dev-statechart/references/runtime.md +21 -1
- package/skills/dev/dev-statechart/scripts/lean/backends/lemma-chart.mjs +285 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/mermaid.mjs +174 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/proof-chart.mjs +540 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/report.mjs +242 -0
- package/skills/dev/dev-statechart/scripts/lean/frontends/facts.mjs +234 -0
- package/skills/dev/dev-statechart/scripts/lean/frontends/view.mjs +217 -0
- package/skills/dev/dev-statechart/scripts/lean/ir.mjs +226 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/attribute.mjs +148 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/blocks.mjs +32 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/budget.mjs +167 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/check.mjs +70 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/contract.mjs +160 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/fold.mjs +206 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/inline.mjs +84 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/mark.mjs +432 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/reduce.mjs +73 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/trust.mjs +111 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/view-lemmas.mjs +155 -0
- package/skills/dev/dev-statechart/scripts/lean/pipeline.mjs +164 -0
- package/skills/dev/dev-statechart/scripts/lean/run.mjs +168 -0
- package/skills/dev/dev-statechart/scripts/statechart.mjs +42 -23
- package/skills/dev/dev-statechart/scripts/worker.mjs +33 -7
- package/skills/dev/dev-ui-design/SKILL.md +2 -2
- package/skills/dev/dev-ui-design/references/interaction-review.md +9 -0
- package/skills/dev/dev-verify/SKILL.md +1 -1
- package/skills/dev/dev-verify/references/evidence-storage.md +12 -0
- package/skills/dev/dev-workflow/SKILL.md +6 -6
- package/skills/dev/dev-workflow/references/method-handoffs.md +7 -1
- package/skills/dev/dev-writing/SKILL.md +2 -0
- package/skills/dev/dev-writing/references/library-docs.md +37 -0
- package/skills/home/home-doctor/references/diagnosis.md +2 -2
- package/skills/home/home-doctor/scripts/doctor.mjs +68 -38
- package/skills/home/home-project-changelog/SKILL.md +7 -7
- package/skills/home/home-project-changelog/assets/project-changelog.example.json +188 -0
- package/skills/home/home-project-changelog/assets/project-changelog.schema.json +156 -0
- package/skills/home/home-project-changelog/assets/worker-brief.md +1 -1
- package/skills/home/home-project-changelog/references/git-ranges.md +2 -2
- package/skills/home/home-project-changelog/references/schema.md +61 -0
- package/skills/home/home-project-changelog/references/tools.md +28 -22
- package/skills/home/home-project-changelog/references/workflow.md +12 -9
- package/skills/home/home-project-changelog/references/writing.md +5 -3
- package/skills/home/home-project-changelog/scripts/changelog.mjs +42 -38
- package/skills/home/home-project-changelog/scripts/contract.mjs +40 -3
- package/skills/home/home-project-changelog/scripts/legacy-markdown.mjs +116 -0
- package/skills/home/home-project-changelog/scripts/migrate.mjs +122 -0
- package/skills/home/home-project-changelog/scripts/revision.mjs +2 -196
- package/skills/home/home-project-changelog/scripts/storage.mjs +120 -125
- package/skills/home/home-project-changelog/scripts/summary.mjs +0 -60
- package/skills/home/home-route/SKILL.md +2 -2
- package/skills/home/home-route/references/routing.md +3 -1
- package/skills/home/home-route/scripts/route.mjs +79 -11
- package/skills/home/home-setup/SKILL.md +2 -1
- package/skills/home/home-setup/assets/repos.schema.json +10 -0
- package/skills/home/home-setup/references/registry.md +18 -1
- package/skills/home/home-setup/scripts/registry.mjs +67 -7
- package/skills/home/home-website/SKILL.md +13 -9
- package/skills/home/home-website/assets/website/scripts/inputs.mjs +143 -128
- package/skills/home/home-website/assets/website/scripts/render.mjs +8 -6
- package/skills/home/home-website/assets/website/scripts/site.mjs +21 -10
- package/skills/home/home-website/assets/website/site/public/home-assets/app.js +81 -34
- package/skills/home/home-website/assets/website/site/public/home-assets/site.css +92 -70
- package/skills/home/home-website/assets/website/site/templates/favicon.png +0 -0
- package/skills/home/home-website/assets/website/site/templates/layout.mjs +13 -10
- package/skills/home/home-website/assets/website/site/templates/ledger.mjs +51 -46
- package/skills/home/home-website/assets/website/site/templates/model.mjs +58 -14
- package/skills/home/home-website/assets/website/site/templates/pages.mjs +28 -30
- package/skills/home/home-website/assets/website/site/templates/project-logs.mjs +3 -107
- package/skills/home/home-website/assets/website/site.config.json +1 -1
- package/skills/home/home-website/references/website.md +64 -46
- package/skills/home/home-website/scripts/activate.mjs +106 -0
- package/skills/home/home-website/scripts/init.mjs +98 -11
- package/skills/home/home-workflow/SKILL.md +6 -4
- package/skills/system/system-clash-proxy-config/SKILL.md +21 -0
- package/skills/system/system-clash-proxy-config/agents/openai.yaml +4 -0
- package/skills/system/system-clash-proxy-config/assets/clash-override.js +328 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/browser-privacy.md +2 -2
- package/skills/system/{system-config → system-clash-proxy-config}/references/changes.md +2 -2
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/clash-verge.md +1 -1
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/diagnosis.md +1 -1
- package/skills/system/system-clash-proxy-config/references/dns-workflow.md +42 -0
- package/skills/system/system-clash-proxy-config/references/egress-macos.md +31 -0
- package/skills/system/system-clash-proxy-config/references/egress-windows.md +37 -0
- package/skills/system/system-clash-proxy-config/references/egress.md +12 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/flclash.md +1 -1
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/index.md +1 -1
- package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/linux-cutover.md +29 -0
- package/skills/system/system-clash-proxy-config/references/locale-workflow.md +9 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/mihomo.md +1 -25
- package/skills/system/system-clash-proxy-config/references/session.md +34 -0
- package/skills/system/system-clash-proxy-config/references/subscription.md +29 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/troubleshooting.md +7 -7
- package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/verification.md +2 -0
- package/skills/system/system-clash-proxy-config/scripts/prepare-session.mjs +155 -0
- package/skills/system/system-clash-proxy-config/scripts/run-session.mjs +138 -0
- package/skills/system/system-inspect/SKILL.md +1 -1
- package/skills/system/system-inspect/references/health-audit.md +1 -1
- package/upstream-skills/zh-archify/SKILL.md +11 -11
- package/upstream-skills/zh-archify/assets/template.html +6 -3
- package/upstream-skills/zh-archify/bin/archify.mjs +67 -4
- package/upstream-skills/zh-archify/modules/code-analysis/ARCHITECTURE.md +7 -1
- package/upstream-skills/zh-archify/modules/code-analysis/bin/analyze-run.mjs +2 -1
- package/upstream-skills/zh-archify/modules/code-analysis/bin/check.mjs +29 -15
- package/upstream-skills/zh-archify/modules/code-analysis/bin/drift.mjs +3 -3
- package/upstream-skills/zh-archify/modules/code-analysis/bin/prepare.mjs +5 -6
- package/upstream-skills/zh-archify/modules/code-analysis/bin/serve.mjs +66 -36
- package/upstream-skills/zh-archify/modules/code-analysis/bin/verify-change.mjs +43 -13
- package/upstream-skills/zh-archify/modules/code-analysis/docs/TECH-GUIDE.md +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/docs/USAGE.md +37 -4
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/functions.mjs +7 -5
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/index.mjs +4 -1
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/snapshot-host.mjs +9 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/architecture-drift.mjs +28 -7
- package/upstream-skills/zh-archify/modules/code-analysis/lib/drift-capture.mjs +4 -3
- package/upstream-skills/zh-archify/modules/code-analysis/lib/git-sources.mjs +5 -3
- package/upstream-skills/zh-archify/modules/code-analysis/lib/output.mjs +272 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/pull-request.mjs +34 -4
- package/upstream-skills/zh-archify/modules/code-analysis/lib/task.mjs +4 -2
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-context.mjs +13 -1
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-history.mjs +112 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification.mjs +6 -2
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/atlas.mjs +71 -5
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.css +16 -2
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.js +121 -5
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas3d.js +38 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.css +14 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.js +187 -27
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/verification.js +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/i18n.mjs +9 -0
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/inject.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/page.mjs +11 -6
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/pull-request.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/schemas/ai-task.schema.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/atlas.test.mjs +88 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/duplicates.test.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/external-workflow.test.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.missing.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.valid.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.changed.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/module-cycle.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/function-source-range.test.mjs +10 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/output-recovery.test.mjs +626 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/pull-request.test.mjs +98 -2
- package/upstream-skills/zh-archify/modules/code-analysis/test/review.test.mjs +37 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/source-panel.test.mjs +2 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/task.test.mjs +3 -2
- package/upstream-skills/zh-archify/modules/code-analysis/test/verification-history.test.mjs +216 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/verification.test.mjs +122 -0
- package/upstream-skills/zh-archify/package-lock.json +2 -2
- package/upstream-skills/zh-archify/package.json +1 -1
- package/upstream-skills/zh-archify/references/authoring-contract.md +2 -0
- package/upstream-skills/zh-archify/references/explainer-authoring.md +1 -1
- package/upstream-skills/zh-archify/renderers/architecture/render-architecture.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/class/render-class.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/dataflow/render-dataflow.mjs +2 -1
- package/upstream-skills/zh-archify/renderers/erd/render-erd.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/lifecycle/render-lifecycle.mjs +4 -2
- package/upstream-skills/zh-archify/renderers/sequence/render-sequence.mjs +4 -2
- package/upstream-skills/zh-archify/renderers/shared/cli.mjs +7 -1
- package/upstream-skills/zh-archify/renderers/timeline/render-timeline.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/tree/render-tree.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/waterfall/render-waterfall.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/workflow/render-workflow.mjs +3 -2
- package/upstream-skills/zh-archify/renderers/workflow/workflow-compiler.mjs +68 -7
- package/upstream-skills/zh-archify/skill-release.json +1 -1
- package/upstream-skills/zh-modern-web-guidance/SKILL.md +4 -11
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-detection.md +20 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-model.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/prompt-api.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/summarizer.md +20 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/translator.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/custom-ml-model-inference.md +342 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/data-parallel-computation.md +337 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/improve-next-page-load-performance.md +4 -1
- package/upstream-skills/zh-modern-web-guidance/guides/performance/large-scene-rendering.md +350 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/position-aware-tooltips.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/viewport-aware-dropdowns.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/animate-to-from-top-layer.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/declarative-dialog-popover-control.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/interest-triggered-tooltips.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/scroll-target-on-load.md +29 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/sortable-table.md +1 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/app-menus.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/context-menu.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/copy-button.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/dialog.md +10 -1
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/hovercard.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/menu.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/navbar.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-app-tours.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-toast-notifications.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/toolbar.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/user-experience/content-first-noise-reduction.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/user-experience/natural-interactions.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/webmcp/agentic-javascript-tools.md +27 -0
- package/skills/home/home-project-changelog/assets/project-changelog.md +0 -35
- package/skills/system/system-clash-tun-egress/SKILL.md +0 -22
- package/skills/system/system-clash-tun-egress/agents/openai.yaml +0 -4
- package/skills/system/system-config/SKILL.md +0 -37
- package/skills/system/system-config/agents/openai.yaml +0 -4
- package/skills/system/system-config/references/ai-cli-config.md +0 -75
- package/skills/system/system-config/references/ai-cli-optimization.md +0 -37
- package/skills/system/system-config/references/index.md +0 -12
- package/skills/system/system-config/references/locale-workflow.md +0 -33
- package/skills/system/system-config/references/locale.md +0 -50
- package/skills/system/system-proxy/SKILL.md +0 -40
- package/skills/system/system-proxy/agents/openai.yaml +0 -4
- package/skills/system/system-proxy/assets/protected-rules.yaml +0 -7
- package/skills/system/system-proxy/references/dns-workflow.md +0 -152
- /package/skills/system/{system-config → system-clash-proxy-config}/assets/configuration.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/assets/network.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/acceptance.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-fields.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-misconceptions.md +0 -0
- /package/skills/system/{system-clash-tun-egress/references/troubleshooting.md → system-clash-proxy-config/references/egress-troubleshooting.md} +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-linux.md +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-macos.md +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-windows.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/network-performance.md +0 -0
- /package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/nodes-and-dns.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platform-dns.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platforms.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/tun-dns.md +0 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { execFile, spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { once } from 'node:events';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { test } from 'node:test';
|
|
9
|
+
import { setTimeout as pause } from 'node:timers/promises';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { runCheck } from '../bin/check.mjs';
|
|
12
|
+
import { prepareAnalysisView } from '../bin/prepare.mjs';
|
|
13
|
+
import { startAnalysisView } from '../bin/serve.mjs';
|
|
14
|
+
import { withAnalysisOutput } from '../lib/output.mjs';
|
|
15
|
+
|
|
16
|
+
const check = fileURLToPath(new URL('../bin/check.mjs', import.meta.url));
|
|
17
|
+
const prepare = fileURLToPath(new URL('../bin/prepare.mjs', import.meta.url));
|
|
18
|
+
const read = file => JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
19
|
+
|
|
20
|
+
function fixture(t) {
|
|
21
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-output-recovery-'));
|
|
22
|
+
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
|
|
23
|
+
const root = path.join(directory, 'repo'), out = path.join(directory, 'out');
|
|
24
|
+
fs.mkdirSync(root);
|
|
25
|
+
const write = (cycle = false) => {
|
|
26
|
+
fs.writeFileSync(path.join(root, 'a.ts'), cycle ? "import { b } from './b'; export const a = b;" : 'export const a = 1;');
|
|
27
|
+
fs.writeFileSync(path.join(root, 'b.ts'), cycle ? "import { a } from './a'; export const b = a;" : 'export const b = 2;');
|
|
28
|
+
};
|
|
29
|
+
write();
|
|
30
|
+
return { directory, root, out, write, args: [root, '--out', out, '--language', 'ts'] };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function fingerprints(directory, names = fs.readdirSync(directory)) {
|
|
34
|
+
return Object.fromEntries(names.sort().map(name => {
|
|
35
|
+
const bytes = fs.readFileSync(path.join(directory, name));
|
|
36
|
+
return [name, createHash('sha256').update(bytes).digest('hex')];
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ioError = () => Object.assign(new Error('injected analysis output error'), { code: 'EIO' });
|
|
41
|
+
|
|
42
|
+
async function startWorkbench(t, args) {
|
|
43
|
+
const view = await startAnalysisView(args);
|
|
44
|
+
t.after(() => new Promise(resolve => {
|
|
45
|
+
view.server.close(resolve);
|
|
46
|
+
view.server.closeAllConnections();
|
|
47
|
+
}));
|
|
48
|
+
return view;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function expectTaskDiagnostic(view, status, code) {
|
|
52
|
+
const response = await fetch(view.url + '/task', {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: { Origin: view.url, 'x-analysis-token': view.token },
|
|
55
|
+
body: JSON.stringify({ ids: ['CMP-0001'] }),
|
|
56
|
+
});
|
|
57
|
+
const body = await response.json();
|
|
58
|
+
assert.equal(response.status, status, JSON.stringify(body));
|
|
59
|
+
assert.equal(body.diagnostics[0].code, code);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function waitFor(file) {
|
|
63
|
+
const deadline = Date.now() + 12000;
|
|
64
|
+
while (!fs.existsSync(file)) {
|
|
65
|
+
assert.ok(Date.now() < deadline, 'the analysis process did not reach the test boundary');
|
|
66
|
+
await pause(15);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
test('a regular file at the lock path yields an output path conflict', async t => {
|
|
71
|
+
const f = fixture(t);
|
|
72
|
+
fs.mkdirSync(f.out);
|
|
73
|
+
const lock = path.join(f.out, '.archify-analysis.lock');
|
|
74
|
+
fs.writeFileSync(lock, 'keep this file');
|
|
75
|
+
await assert.rejects(runCheck(f.args), error =>
|
|
76
|
+
error.diagnostics?.[0]?.code === 'analysis/output-path-conflict' && error.diagnostics[0].subject.file === lock);
|
|
77
|
+
assert.equal(fs.readFileSync(lock, 'utf8'), 'keep this file');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('check rejects a directory at the automatic comparison path before reading it', async t => {
|
|
81
|
+
const f = fixture(t);
|
|
82
|
+
const findings = path.join(f.out, 'findings.json');
|
|
83
|
+
fs.mkdirSync(findings, { recursive: true });
|
|
84
|
+
const { readFileSync } = fs;
|
|
85
|
+
let readFindings = false;
|
|
86
|
+
fs.readFileSync = (file, ...args) => {
|
|
87
|
+
if (file === findings) readFindings = true;
|
|
88
|
+
return readFileSync(file, ...args);
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
await assert.rejects(runCheck(f.args), error =>
|
|
92
|
+
error.diagnostics?.[0]?.code === 'analysis/output-path-conflict' && error.diagnostics[0].subject.file === findings);
|
|
93
|
+
} finally {
|
|
94
|
+
fs.readFileSync = readFileSync;
|
|
95
|
+
}
|
|
96
|
+
assert.equal(readFindings, false, 'check attempted to read the directory as a file');
|
|
97
|
+
assert.deepEqual(fs.readdirSync(f.out), ['findings.json']);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a failed check publication keeps the previous reports and fails the gate on retry', async t => {
|
|
101
|
+
const f = fixture(t);
|
|
102
|
+
const run = (...args) => runCheck([...f.args, '--new-only', ...args]);
|
|
103
|
+
assert.equal((await run()).exitCode, 0);
|
|
104
|
+
const comparison = path.join(f.directory, 'explicit-previous.json');
|
|
105
|
+
fs.copyFileSync(path.join(f.out, 'findings.json'), comparison);
|
|
106
|
+
fs.writeFileSync(path.join(f.out, 'user-note.txt'), 'keep this file');
|
|
107
|
+
const before = fingerprints(f.out);
|
|
108
|
+
f.write(true);
|
|
109
|
+
|
|
110
|
+
const overview = path.join(f.out, 'overview.json');
|
|
111
|
+
const { renameSync, writeFileSync } = fs;
|
|
112
|
+
fs.renameSync = (from, to) => {
|
|
113
|
+
if (to === overview && path.basename(path.dirname(from)) === 'next') throw ioError();
|
|
114
|
+
return renameSync(from, to);
|
|
115
|
+
};
|
|
116
|
+
fs.writeFileSync = (target, ...args) => {
|
|
117
|
+
// Also exercises the old in-place writer at the equivalent boundary.
|
|
118
|
+
if (target === overview) throw ioError();
|
|
119
|
+
return writeFileSync(target, ...args);
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
await assert.rejects(run(), { code: 'EIO' });
|
|
123
|
+
} finally {
|
|
124
|
+
Object.assign(fs, { renameSync, writeFileSync });
|
|
125
|
+
}
|
|
126
|
+
assert.deepEqual(fingerprints(f.out), before);
|
|
127
|
+
|
|
128
|
+
const retry = await run();
|
|
129
|
+
assert.equal(retry.exitCode, 1);
|
|
130
|
+
assert.ok(retry.receipt.gate.failing.some(finding => finding.code === 'coupling/import-cycle'));
|
|
131
|
+
assert.equal((await run()).exitCode, 0, 'the complete gate-failing run becomes the next comparison');
|
|
132
|
+
assert.equal((await run('--compare', comparison)).exitCode, 1);
|
|
133
|
+
assert.equal(fs.readFileSync(path.join(f.out, 'user-note.txt'), 'utf8'), 'keep this file');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('a failed prepare publication restores both reports and compares with the last complete run on retry', async t => {
|
|
137
|
+
const f = fixture(t);
|
|
138
|
+
const current = path.join(f.out, 'analysis'), previous = path.join(f.out, 'analysis.previous');
|
|
139
|
+
await prepareAnalysisView(f.args);
|
|
140
|
+
const first = fingerprints(current);
|
|
141
|
+
fs.writeFileSync(path.join(f.root, 'a.ts'), 'export const a = 3;');
|
|
142
|
+
await prepareAnalysisView(f.args);
|
|
143
|
+
const lastGood = fingerprints(current);
|
|
144
|
+
assert.deepEqual(fingerprints(previous), first);
|
|
145
|
+
const rename = fs.renameSync;
|
|
146
|
+
fs.renameSync = (from, to) => {
|
|
147
|
+
if (to === current && from !== previous) throw ioError();
|
|
148
|
+
return rename(from, to);
|
|
149
|
+
};
|
|
150
|
+
f.write(true);
|
|
151
|
+
try {
|
|
152
|
+
await assert.rejects(prepareAnalysisView(f.args), { code: 'EIO' });
|
|
153
|
+
} finally {
|
|
154
|
+
fs.renameSync = rename;
|
|
155
|
+
}
|
|
156
|
+
assert.deepEqual(fingerprints(current), lastGood);
|
|
157
|
+
assert.deepEqual(fingerprints(previous), first);
|
|
158
|
+
assert.deepEqual(fs.readdirSync(f.out).sort(), ['analysis', 'analysis.previous']);
|
|
159
|
+
|
|
160
|
+
await prepareAnalysisView(f.args);
|
|
161
|
+
assert.deepEqual(fingerprints(previous), lastGood);
|
|
162
|
+
assert.ok(read(path.join(current, 'review.json')).comparison.new.length > 0);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('a failed rollback still requires recovery while the workbench stays open', async t => {
|
|
166
|
+
const f = fixture(t);
|
|
167
|
+
const current = path.join(f.out, 'analysis'), previous = path.join(f.out, 'analysis.previous');
|
|
168
|
+
const view = await startWorkbench(t, f.args);
|
|
169
|
+
const refresh = async () => {
|
|
170
|
+
const response = await fetch(view.url + '/analyze', {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers: { Origin: view.url, 'x-analysis-token': view.token, 'x-analysis-refresh': '1' },
|
|
173
|
+
});
|
|
174
|
+
const body = await response.text();
|
|
175
|
+
return { status: response.status, diagnostics: response.ok ? [] : JSON.parse(body).diagnostics };
|
|
176
|
+
};
|
|
177
|
+
assert.equal((await refresh()).status, 200);
|
|
178
|
+
const older = fingerprints(current);
|
|
179
|
+
fs.writeFileSync(path.join(f.root, 'a.ts'), 'export const a = 3;');
|
|
180
|
+
assert.equal((await refresh()).status, 200);
|
|
181
|
+
const lastGood = fingerprints(current);
|
|
182
|
+
f.write(true);
|
|
183
|
+
|
|
184
|
+
const rename = fs.renameSync;
|
|
185
|
+
fs.renameSync = (from, to) => {
|
|
186
|
+
// Both publishing the staged report and restoring the current one fail.
|
|
187
|
+
if (to === current) throw ioError();
|
|
188
|
+
return rename(from, to);
|
|
189
|
+
};
|
|
190
|
+
let failed;
|
|
191
|
+
try {
|
|
192
|
+
failed = await refresh();
|
|
193
|
+
} finally {
|
|
194
|
+
fs.renameSync = rename;
|
|
195
|
+
}
|
|
196
|
+
assert.equal(failed.status, 500);
|
|
197
|
+
assert.equal(failed.diagnostics[0].code, 'analysis/output-recovery-required');
|
|
198
|
+
|
|
199
|
+
const retry = await refresh();
|
|
200
|
+
assert.equal(retry.status, 500);
|
|
201
|
+
assert.equal(retry.diagnostics[0].code, 'analysis/output-recovery-required');
|
|
202
|
+
const plan = retry.diagnostics[0].subject.plan;
|
|
203
|
+
assert.equal(failed.diagnostics[0].subject.plan, plan);
|
|
204
|
+
const separate = spawnSync(process.execPath, [prepare, ...f.args], { encoding: 'utf8', timeout: 12000 });
|
|
205
|
+
assert.equal(separate.status, 2, separate.stdout + separate.stderr);
|
|
206
|
+
const [diagnostic] = JSON.parse(separate.stdout).diagnostics;
|
|
207
|
+
assert.equal(diagnostic.code, 'analysis/output-recovery-required');
|
|
208
|
+
assert.equal(diagnostic.subject.plan, plan);
|
|
209
|
+
assert.deepEqual(fingerprints(previous), lastGood);
|
|
210
|
+
const backup = read(plan).find(([from]) => from === previous)?.[1];
|
|
211
|
+
assert.ok(backup, 'the move plan identifies the backup of the older report');
|
|
212
|
+
assert.deepEqual(fingerprints(backup), older);
|
|
213
|
+
assert.equal(fs.existsSync(current), false);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('a workbench retry requires recovery even when the rollback marker could not be written', async t => {
|
|
217
|
+
const f = fixture(t);
|
|
218
|
+
await prepareAnalysisView(f.args);
|
|
219
|
+
const view = await startWorkbench(t, f.args);
|
|
220
|
+
const current = path.join(f.out, 'analysis');
|
|
221
|
+
const refresh = () => fetch(view.url + '/analyze', {
|
|
222
|
+
method: 'POST',
|
|
223
|
+
headers: { Origin: view.url, 'x-analysis-token': view.token, 'x-analysis-refresh': '1' },
|
|
224
|
+
});
|
|
225
|
+
const { renameSync, writeFileSync } = fs;
|
|
226
|
+
fs.renameSync = (from, to) => {
|
|
227
|
+
if (to === current) throw ioError();
|
|
228
|
+
return renameSync(from, to);
|
|
229
|
+
};
|
|
230
|
+
fs.writeFileSync = (file, ...args) => {
|
|
231
|
+
if (path.basename(file) === 'rollback-failed') throw Object.assign(new Error('no space for rollback marker'), { code: 'ENOSPC' });
|
|
232
|
+
return writeFileSync(file, ...args);
|
|
233
|
+
};
|
|
234
|
+
try {
|
|
235
|
+
const failed = await refresh();
|
|
236
|
+
assert.equal(failed.status, 500);
|
|
237
|
+
const [diagnostic] = (await failed.json()).diagnostics;
|
|
238
|
+
assert.equal(diagnostic.code, 'analysis/output-recovery-required');
|
|
239
|
+
assert.equal(diagnostic.evidence.recoveryMarkerError, 'no space for rollback marker');
|
|
240
|
+
assert.ok(fs.existsSync(diagnostic.subject.plan));
|
|
241
|
+
} finally {
|
|
242
|
+
Object.assign(fs, { renameSync, writeFileSync });
|
|
243
|
+
}
|
|
244
|
+
const retry = await refresh();
|
|
245
|
+
assert.equal(retry.status, 500);
|
|
246
|
+
assert.equal((await retry.json()).diagnostics[0].code, 'analysis/output-recovery-required');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('check owns the previous findings through publication and installs the new findings last', { timeout: 45000 }, async t => {
|
|
250
|
+
const f = fixture(t);
|
|
251
|
+
const args = [...f.args, '--new-only', '--json'];
|
|
252
|
+
assert.equal((await runCheck(args)).exitCode, 0);
|
|
253
|
+
const before = fingerprints(f.out);
|
|
254
|
+
f.write(true);
|
|
255
|
+
const hook = path.join(f.directory, 'hold-check.cjs');
|
|
256
|
+
fs.writeFileSync(hook, `
|
|
257
|
+
const fs = require('node:fs');
|
|
258
|
+
const path = require('node:path');
|
|
259
|
+
const directory = ${JSON.stringify(f.directory)};
|
|
260
|
+
const out = ${JSON.stringify(f.out)};
|
|
261
|
+
const { readFileSync, renameSync } = fs;
|
|
262
|
+
function hold(event) {
|
|
263
|
+
fs.writeFileSync(path.join(directory, event), '');
|
|
264
|
+
const release = path.join(directory, event + '-release');
|
|
265
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
266
|
+
const deadline = Date.now() + 25000;
|
|
267
|
+
while (!fs.existsSync(release) && Date.now() < deadline) Atomics.wait(wait, 0, 0, 15);
|
|
268
|
+
if (!fs.existsSync(release)) throw new Error('Timed out after ' + event);
|
|
269
|
+
}
|
|
270
|
+
fs.readFileSync = (file, ...args) => {
|
|
271
|
+
const bytes = readFileSync(file, ...args);
|
|
272
|
+
if (file === path.join(out, 'findings.json')) hold('compared');
|
|
273
|
+
return bytes;
|
|
274
|
+
};
|
|
275
|
+
fs.renameSync = (from, to) => {
|
|
276
|
+
if (to === path.join(out, 'overview.json') && path.basename(path.dirname(from)) === 'next') {
|
|
277
|
+
hold('before-overview');
|
|
278
|
+
}
|
|
279
|
+
return renameSync(from, to);
|
|
280
|
+
};
|
|
281
|
+
`);
|
|
282
|
+
const release = event => fs.writeFileSync(path.join(f.directory, event + '-release'), '');
|
|
283
|
+
const first = new Promise(resolve => {
|
|
284
|
+
execFile(process.execPath, ['--require', hook, check, ...args], { encoding: 'utf8', timeout: 40000 },
|
|
285
|
+
(error, stdout, stderr) => resolve({ error, stdout, stderr }));
|
|
286
|
+
});
|
|
287
|
+
const checkAgain = () => spawnSync(process.execPath, [check, ...args], { encoding: 'utf8', timeout: 12000 });
|
|
288
|
+
try {
|
|
289
|
+
await waitFor(path.join(f.directory, 'compared'));
|
|
290
|
+
const second = checkAgain();
|
|
291
|
+
assert.equal(second.status, 2, second.stdout + second.stderr);
|
|
292
|
+
assert.equal(JSON.parse(second.stdout).diagnostics[0].code, 'analysis/output-busy');
|
|
293
|
+
assert.deepEqual(fingerprints(f.out, Object.keys(before)), before);
|
|
294
|
+
release('compared');
|
|
295
|
+
await waitFor(path.join(f.directory, 'before-overview'));
|
|
296
|
+
assert.deepEqual(fingerprints(f.out, ['findings.json']), { 'findings.json': before['findings.json'] });
|
|
297
|
+
} finally {
|
|
298
|
+
release('compared');
|
|
299
|
+
release('before-overview');
|
|
300
|
+
await first;
|
|
301
|
+
}
|
|
302
|
+
const completed = await first;
|
|
303
|
+
assert.equal(completed.error?.code, 1, completed.stdout + completed.stderr);
|
|
304
|
+
assert.ok(JSON.parse(completed.stdout).gate.failing.some(finding => finding.code === 'coupling/import-cycle'));
|
|
305
|
+
const retry = checkAgain();
|
|
306
|
+
assert.equal(retry.status, 0, retry.stdout + retry.stderr);
|
|
307
|
+
assert.deepEqual(JSON.parse(retry.stdout).gate.failing, []);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('Linux reclaims a reused PID only when process and clock identities can be compared', {
|
|
311
|
+
skip: process.platform !== 'linux',
|
|
312
|
+
}, async t => {
|
|
313
|
+
const f = fixture(t);
|
|
314
|
+
const { readFileSync, statSync } = fs;
|
|
315
|
+
const kill = process.kill;
|
|
316
|
+
let boot = '00000000-0000-0000-0000-000000000001';
|
|
317
|
+
let pidNamespace = 123n;
|
|
318
|
+
let timeNamespace = 456n;
|
|
319
|
+
let procPids = String(process.pid);
|
|
320
|
+
let started = '100';
|
|
321
|
+
let visible = true;
|
|
322
|
+
// Emulate distinct Linux process views without requiring namespace privileges in CI.
|
|
323
|
+
fs.statSync = (file, ...args) => {
|
|
324
|
+
if (file === '/proc/self/ns/pid') return { dev: 1n, ino: pidNamespace };
|
|
325
|
+
if (file === '/proc/self/ns/time') return { dev: 1n, ino: timeNamespace };
|
|
326
|
+
return statSync(file, ...args);
|
|
327
|
+
};
|
|
328
|
+
fs.readFileSync = (file, ...args) => {
|
|
329
|
+
if (file === '/proc/sys/kernel/random/boot_id') return boot + '\n';
|
|
330
|
+
if (file === '/proc/self/status') return `NStgid:\t${procPids}\n`;
|
|
331
|
+
if (file === '/proc/self/stat' || file === '/proc/' + process.pid + '/stat') {
|
|
332
|
+
return process.pid + ' (node) worker) S ' + '0 '.repeat(18) + started + ' 0\n';
|
|
333
|
+
}
|
|
334
|
+
return readFileSync(file, ...args);
|
|
335
|
+
};
|
|
336
|
+
process.kill = (pid, signal) => {
|
|
337
|
+
if (pid !== process.pid || signal !== 0) return kill(pid, signal);
|
|
338
|
+
if (!visible) throw Object.assign(new Error('not visible in this namespace'), { code: 'ESRCH' });
|
|
339
|
+
return true;
|
|
340
|
+
};
|
|
341
|
+
try {
|
|
342
|
+
let original;
|
|
343
|
+
await withAnalysisOutput(f.out, workspace => { original = workspace; });
|
|
344
|
+
fs.mkdirSync(original, { recursive: true });
|
|
345
|
+
const staged = path.join(original, 'staged.json');
|
|
346
|
+
fs.writeFileSync(staged, 'previous staging');
|
|
347
|
+
const expectBusy = async () => {
|
|
348
|
+
await assert.rejects(withAnalysisOutput(f.out, () => assert.fail('a foreign writer took the lock')),
|
|
349
|
+
error => error.diagnostics?.[0]?.code === 'analysis/output-busy');
|
|
350
|
+
assert.equal(fs.readFileSync(staged, 'utf8'), 'previous staging');
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
pidNamespace = 124n;
|
|
354
|
+
visible = false;
|
|
355
|
+
await expectBusy();
|
|
356
|
+
|
|
357
|
+
pidNamespace = 123n;
|
|
358
|
+
boot = '00000000-0000-0000-0000-000000000002';
|
|
359
|
+
await expectBusy();
|
|
360
|
+
|
|
361
|
+
boot = '00000000-0000-0000-0000-000000000001';
|
|
362
|
+
timeNamespace = 457n;
|
|
363
|
+
visible = true;
|
|
364
|
+
started = '200';
|
|
365
|
+
await expectBusy();
|
|
366
|
+
|
|
367
|
+
timeNamespace = 456n;
|
|
368
|
+
procPids = `42\t${process.pid}`;
|
|
369
|
+
await expectBusy();
|
|
370
|
+
|
|
371
|
+
procPids = String(process.pid);
|
|
372
|
+
await withAnalysisOutput(f.out, workspace => {
|
|
373
|
+
assert.notEqual(workspace, original);
|
|
374
|
+
assert.equal(fs.existsSync(original), false);
|
|
375
|
+
assert.deepEqual(fs.readdirSync(workspace), []);
|
|
376
|
+
});
|
|
377
|
+
} finally {
|
|
378
|
+
Object.assign(fs, { readFileSync, statSync });
|
|
379
|
+
process.kill = kill;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('a second prepare process cannot publish into an output directory in use', { timeout: 45000 }, async t => {
|
|
384
|
+
const f = fixture(t);
|
|
385
|
+
await prepareAnalysisView(f.args);
|
|
386
|
+
const view = await startWorkbench(t, f.args);
|
|
387
|
+
f.write(true);
|
|
388
|
+
const current = path.join(f.out, 'analysis');
|
|
389
|
+
const original = fingerprints(current);
|
|
390
|
+
const ready = path.join(f.directory, 'ready'), release = path.join(f.directory, 'release');
|
|
391
|
+
const hook = path.join(f.directory, 'hold-publication.cjs');
|
|
392
|
+
fs.writeFileSync(hook, `
|
|
393
|
+
const fs = require('node:fs');
|
|
394
|
+
const { current, ready, release } = JSON.parse(process.env.ARCHIFY_TEST_PUBLICATION);
|
|
395
|
+
const rename = fs.renameSync;
|
|
396
|
+
fs.renameSync = (from, to) => {
|
|
397
|
+
if (from === current) {
|
|
398
|
+
fs.writeFileSync(ready, '');
|
|
399
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
400
|
+
const deadline = Date.now() + 25000;
|
|
401
|
+
while (!fs.existsSync(release) && Date.now() < deadline) Atomics.wait(wait, 0, 0, 15);
|
|
402
|
+
if (!fs.existsSync(release)) throw new Error('Timed out waiting to publish');
|
|
403
|
+
}
|
|
404
|
+
return rename(from, to);
|
|
405
|
+
};
|
|
406
|
+
`);
|
|
407
|
+
const first = new Promise(resolve => {
|
|
408
|
+
execFile(process.execPath, ['--require', hook, prepare, ...f.args], {
|
|
409
|
+
encoding: 'utf8', timeout: 40000, env: { ...process.env, ARCHIFY_TEST_PUBLICATION: JSON.stringify({ current, ready, release }) },
|
|
410
|
+
}, (error, stdout, stderr) => resolve({ error, stdout, stderr }));
|
|
411
|
+
});
|
|
412
|
+
try {
|
|
413
|
+
await waitFor(ready);
|
|
414
|
+
await expectTaskDiagnostic(view, 409, 'analysis/output-busy');
|
|
415
|
+
const second = spawnSync(process.execPath, [prepare, ...f.args], { encoding: 'utf8', timeout: 12000 });
|
|
416
|
+
assert.equal(second.status, 2, second.stdout + second.stderr);
|
|
417
|
+
assert.equal(JSON.parse(second.stdout).diagnostics[0].code, 'analysis/output-busy');
|
|
418
|
+
assert.deepEqual(fingerprints(current), original);
|
|
419
|
+
} finally {
|
|
420
|
+
fs.writeFileSync(release, '');
|
|
421
|
+
await first;
|
|
422
|
+
}
|
|
423
|
+
const done = await first;
|
|
424
|
+
assert.ifError(done.error);
|
|
425
|
+
assert.deepEqual(fingerprints(path.join(f.out, 'analysis.previous')), original);
|
|
426
|
+
assert.ok(read(path.join(current, 'review.json')).comparison.new.length > 0);
|
|
427
|
+
|
|
428
|
+
await prepareAnalysisView(f.args);
|
|
429
|
+
assert.deepEqual(read(path.join(current, 'review.json')).comparison.new, []);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('a retry discards the staged report of a process stopped before publication', { timeout: 30000 }, async t => {
|
|
433
|
+
const f = fixture(t);
|
|
434
|
+
await prepareAnalysisView(f.args);
|
|
435
|
+
const current = path.join(f.out, 'analysis');
|
|
436
|
+
const original = fingerprints(current);
|
|
437
|
+
f.write(true);
|
|
438
|
+
const ready = path.join(f.directory, 'ready');
|
|
439
|
+
const hook = path.join(f.directory, 'hold-staged-report.cjs');
|
|
440
|
+
fs.writeFileSync(hook, `
|
|
441
|
+
const fs = require('node:fs');
|
|
442
|
+
const path = require('node:path');
|
|
443
|
+
const read = fs.readFileSync;
|
|
444
|
+
fs.readFileSync = (file, ...args) => {
|
|
445
|
+
const value = read(file, ...args);
|
|
446
|
+
if (typeof file === 'string' && path.basename(file) === 'repo.analysis.html'
|
|
447
|
+
&& path.dirname(file) !== ${JSON.stringify(current)}) {
|
|
448
|
+
fs.writeFileSync(${JSON.stringify(ready)}, path.dirname(file));
|
|
449
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 15000);
|
|
450
|
+
throw new Error('Timed out waiting for the test to stop publication');
|
|
451
|
+
}
|
|
452
|
+
return value;
|
|
453
|
+
};
|
|
454
|
+
`);
|
|
455
|
+
const child = spawn(process.execPath, ['--require', hook, prepare, ...f.args], { stdio: 'ignore' });
|
|
456
|
+
const closed = once(child, 'close');
|
|
457
|
+
try {
|
|
458
|
+
await waitFor(ready);
|
|
459
|
+
} finally {
|
|
460
|
+
child.kill('SIGKILL');
|
|
461
|
+
await closed;
|
|
462
|
+
}
|
|
463
|
+
const abandoned = fs.readFileSync(ready, 'utf8');
|
|
464
|
+
assert.ok(fs.existsSync(path.join(abandoned, 'findings.json')), 'the stopped run produced a staged report');
|
|
465
|
+
assert.deepEqual(fingerprints(current), original);
|
|
466
|
+
const unrelated = 'analysis.next-000000000000';
|
|
467
|
+
fs.mkdirSync(path.join(f.out, unrelated));
|
|
468
|
+
fs.writeFileSync(path.join(f.out, unrelated, 'note.txt'), 'keep');
|
|
469
|
+
|
|
470
|
+
const { rmSync } = fs;
|
|
471
|
+
const lock = path.dirname(path.dirname(abandoned));
|
|
472
|
+
fs.rmSync = (target, ...args) => {
|
|
473
|
+
// Emulate staging with contents that remain undeletable until permissions are repaired.
|
|
474
|
+
if (path.dirname(target) === lock || path.dirname(path.dirname(target)) === lock) {
|
|
475
|
+
throw Object.assign(new Error('cannot remove abandoned staging'), { code: 'EACCES' });
|
|
476
|
+
}
|
|
477
|
+
return rmSync(target, ...args);
|
|
478
|
+
};
|
|
479
|
+
try {
|
|
480
|
+
await assert.rejects(prepareAnalysisView(f.args), { code: 'EACCES' });
|
|
481
|
+
} finally {
|
|
482
|
+
fs.rmSync = rmSync;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
await prepareAnalysisView(f.args);
|
|
486
|
+
assert.equal(fs.existsSync(abandoned), false);
|
|
487
|
+
assert.deepEqual(fingerprints(path.join(f.out, 'analysis.previous')), original);
|
|
488
|
+
assert.ok(read(path.join(current, 'review.json')).comparison.new.length > 0);
|
|
489
|
+
|
|
490
|
+
// A worker that starts after its owner is reclaimed must not recreate the lock.
|
|
491
|
+
const worker = fileURLToPath(new URL('../bin/analyze-run.mjs', import.meta.url));
|
|
492
|
+
const orphan = spawnSync(process.execPath, [worker], {
|
|
493
|
+
input: JSON.stringify({ root: f.root, language: 'ts', out: abandoned }), encoding: 'utf8', timeout: 12000,
|
|
494
|
+
});
|
|
495
|
+
assert.equal(orphan.status, 1, orphan.stdout + orphan.stderr);
|
|
496
|
+
assert.deepEqual(fs.readdirSync(f.out).sort(), ['analysis', unrelated, 'analysis.previous']);
|
|
497
|
+
assert.equal(fs.readFileSync(path.join(f.out, unrelated, 'note.txt'), 'utf8'), 'keep');
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test('a prepare process killed during publication leaves both previous reports for recovery', { timeout: 30000 }, async t => {
|
|
501
|
+
const f = fixture(t);
|
|
502
|
+
const current = path.join(f.out, 'analysis'), previous = path.join(f.out, 'analysis.previous');
|
|
503
|
+
await prepareAnalysisView(f.args);
|
|
504
|
+
const first = fingerprints(current);
|
|
505
|
+
fs.writeFileSync(path.join(f.root, 'a.ts'), 'export const a = 3;');
|
|
506
|
+
await prepareAnalysisView(f.args);
|
|
507
|
+
const lastGood = fingerprints(current);
|
|
508
|
+
f.write(true);
|
|
509
|
+
const view = await startWorkbench(t, f.args);
|
|
510
|
+
|
|
511
|
+
const ready = path.join(f.directory, 'ready');
|
|
512
|
+
const hook = path.join(f.directory, 'stop-publication.cjs');
|
|
513
|
+
fs.writeFileSync(hook, `
|
|
514
|
+
const fs = require('node:fs');
|
|
515
|
+
const rename = fs.renameSync;
|
|
516
|
+
fs.renameSync = (from, to) => {
|
|
517
|
+
rename(from, to);
|
|
518
|
+
if (from === ${JSON.stringify(current)}) {
|
|
519
|
+
fs.writeFileSync(${JSON.stringify(ready)}, '');
|
|
520
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25000);
|
|
521
|
+
throw new Error('Timed out waiting for the test to stop publication');
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
`);
|
|
525
|
+
const child = spawn(process.execPath, ['--require', hook, prepare, ...f.args], { stdio: 'ignore' });
|
|
526
|
+
const closed = once(child, 'close');
|
|
527
|
+
try {
|
|
528
|
+
await waitFor(ready);
|
|
529
|
+
} finally {
|
|
530
|
+
child.kill('SIGKILL');
|
|
531
|
+
await closed;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
await expectTaskDiagnostic(view, 500, 'analysis/output-recovery-required');
|
|
535
|
+
const retry = spawnSync(process.execPath, [prepare, ...f.args], { encoding: 'utf8', timeout: 12000 });
|
|
536
|
+
assert.equal(retry.status, 2, retry.stdout + retry.stderr);
|
|
537
|
+
const [diagnostic] = JSON.parse(retry.stdout).diagnostics;
|
|
538
|
+
assert.equal(diagnostic.code, 'analysis/output-recovery-required');
|
|
539
|
+
const backupMove = read(diagnostic.subject.plan).find(([from]) => from === previous);
|
|
540
|
+
assert.ok(backupMove, 'the move plan identifies the backup of the older report');
|
|
541
|
+
assert.deepEqual(fingerprints(backupMove[1]), first);
|
|
542
|
+
assert.deepEqual(fingerprints(previous), lastGood);
|
|
543
|
+
assert.equal(fs.existsSync(current), false, 'the retry did not publish over the interrupted state');
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test('verification history retains the previous report when current output is absent', async t => {
|
|
547
|
+
const f = fixture(t);
|
|
548
|
+
const current = path.join(f.out, 'analysis'), previous = path.join(f.out, 'analysis.previous');
|
|
549
|
+
await pause(1100); // The baseline is captured after the repository creation window.
|
|
550
|
+
await prepareAnalysisView(f.args);
|
|
551
|
+
const before = read(path.join(current, 'findings.json'));
|
|
552
|
+
fs.renameSync(current, previous);
|
|
553
|
+
f.write(true);
|
|
554
|
+
await prepareAnalysisView(f.args);
|
|
555
|
+
const history = read(path.join(current, 'verification-history.json'));
|
|
556
|
+
assert.ok(history.some(item => item.repository.snapshotId === before.repository.snapshotId));
|
|
557
|
+
assert.deepEqual(read(path.join(previous, 'findings.json')), before, 'recovery preserves the previous report');
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
test('an empty output lock cannot be reclaimed during another claim', async t => {
|
|
561
|
+
const f = fixture(t);
|
|
562
|
+
fs.mkdirSync(path.join(f.out, '.archify-analysis.lock'), { recursive: true });
|
|
563
|
+
await assert.rejects(withAnalysisOutput(f.out, () => assert.fail('entered an unowned lock')),
|
|
564
|
+
error => error.diagnostics?.[0]?.code === 'analysis/output-busy');
|
|
565
|
+
assert.deepEqual(fs.readdirSync(path.join(f.out, '.archify-analysis.lock')), []);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test('a failed owner installation removes both the public lock and the private claim', async t => {
|
|
569
|
+
const f = fixture(t);
|
|
570
|
+
const lock = path.join(f.out, '.archify-analysis.lock');
|
|
571
|
+
const { renameSync } = fs;
|
|
572
|
+
for (const code of ['EIO', 'EACCES']) {
|
|
573
|
+
const failedInstall = Object.assign(ioError(), { code });
|
|
574
|
+
fs.renameSync = (from, to) => {
|
|
575
|
+
if (path.dirname(to) === lock && path.basename(path.dirname(from)).startsWith('.archify-analysis.claim-')) {
|
|
576
|
+
assert.deepEqual(fs.readdirSync(lock), []);
|
|
577
|
+
throw failedInstall;
|
|
578
|
+
}
|
|
579
|
+
return renameSync(from, to);
|
|
580
|
+
};
|
|
581
|
+
try {
|
|
582
|
+
await assert.rejects(withAnalysisOutput(f.out, () => assert.fail('entered without an owner')), error => error === failedInstall);
|
|
583
|
+
} finally {
|
|
584
|
+
fs.renameSync = renameSync;
|
|
585
|
+
}
|
|
586
|
+
assert.deepEqual(fs.readdirSync(f.out), []);
|
|
587
|
+
}
|
|
588
|
+
await withAnalysisOutput(f.out, workspace => assert.equal(path.dirname(workspace), lock));
|
|
589
|
+
assert.deepEqual(fs.readdirSync(f.out), []);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test('an older claimant keeps sole ownership when it replaces the empty lock', async t => {
|
|
593
|
+
const f = fixture(t);
|
|
594
|
+
const lock = path.join(f.out, '.archify-analysis.lock');
|
|
595
|
+
const olderClaim = path.join(f.directory, 'older-claim');
|
|
596
|
+
const olderOwner = 'older-owner';
|
|
597
|
+
fs.mkdirSync(path.join(olderClaim, olderOwner), { recursive: true });
|
|
598
|
+
fs.writeFileSync(path.join(olderClaim, olderOwner, 'staged.txt'), 'older report');
|
|
599
|
+
const { renameSync } = fs;
|
|
600
|
+
fs.renameSync = (from, to) => {
|
|
601
|
+
if (path.dirname(to) === lock && path.basename(path.dirname(from)).startsWith('.archify-analysis.claim-')) {
|
|
602
|
+
fs.rmdirSync(lock);
|
|
603
|
+
renameSync(olderClaim, lock);
|
|
604
|
+
}
|
|
605
|
+
return renameSync(from, to);
|
|
606
|
+
};
|
|
607
|
+
try {
|
|
608
|
+
await assert.rejects(withAnalysisOutput(f.out, () => assert.fail('entered another command’s lock')),
|
|
609
|
+
error => error.diagnostics?.[0]?.code === 'analysis/output-busy');
|
|
610
|
+
} finally {
|
|
611
|
+
fs.renameSync = renameSync;
|
|
612
|
+
}
|
|
613
|
+
assert.deepEqual(fs.readdirSync(f.out), ['.archify-analysis.lock']);
|
|
614
|
+
assert.deepEqual(fs.readdirSync(lock), [olderOwner]);
|
|
615
|
+
assert.equal(fs.readFileSync(path.join(lock, olderOwner, 'staged.txt'), 'utf8'), 'older report');
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
test('a new output lock grants access only to its owner on POSIX', {
|
|
619
|
+
skip: process.platform === 'win32',
|
|
620
|
+
}, async t => {
|
|
621
|
+
const f = fixture(t);
|
|
622
|
+
await withAnalysisOutput(f.out, workspace => {
|
|
623
|
+
const mode = fs.statSync(path.dirname(workspace)).mode;
|
|
624
|
+
assert.equal(mode & 0o077, 0);
|
|
625
|
+
});
|
|
626
|
+
});
|