opencode-agent-orchestration-kit 1.0.27
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/.github/CODEOWNERS +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
- package/.github/ISSUE_TEMPLATE/config.yml +11 -0
- package/.github/ISSUE_TEMPLATE/documentation.yml +22 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
- package/.github/workflows/check.yml +47 -0
- package/CODE_OF_CONDUCT.md +24 -0
- package/CONTRIBUTING.md +52 -0
- package/LICENSE +201 -0
- package/NOTICE.md +23 -0
- package/README.md +806 -0
- package/SECURITY.md +17 -0
- package/docker/open-design/.env.example +6 -0
- package/docker/open-design/Dockerfile +50 -0
- package/docker/open-design/docker-compose.yml +18 -0
- package/docker/open-design/opencode-od/agents/od-worker.md +22 -0
- package/docker/open-design/opencode-od/opencode.json +24 -0
- package/docs/agents.md +21 -0
- package/docs/commands.md +16 -0
- package/docs/configuration.md +30 -0
- package/docs/docker-open-design.md +42 -0
- package/docs/impeccable.md +18 -0
- package/docs/installation.md +176 -0
- package/docs/models.md +17 -0
- package/docs/open-design.md +25 -0
- package/docs/quickstart.md +74 -0
- package/docs/releases/v1.0.10.md +46 -0
- package/docs/releases/v1.0.14.md +39 -0
- package/docs/releases/v1.0.27.md +66 -0
- package/docs/security.md +8 -0
- package/docs/superpowers/plans/2026-07-20-safe-installation-lifecycle.md +779 -0
- package/docs/superpowers/plans/2026-07-20-version-identity-and-releases.md +590 -0
- package/docs/superpowers/specs/2026-07-20-safe-installation-lifecycle-design.md +1350 -0
- package/docs/superpowers/specs/2026-07-20-version-identity-and-releases-design.md +557 -0
- package/docs/superpowers.md +34 -0
- package/docs/synology.md +30 -0
- package/docs/troubleshooting.md +54 -0
- package/docs/workflows.md +44 -0
- package/doctor.sh +5 -0
- package/env.example +15 -0
- package/install.sh +5 -0
- package/opencode/AGENTS.md +104 -0
- package/opencode/agents/debugger.md +41 -0
- package/opencode/agents/designer.md +93 -0
- package/opencode/agents/developer.md +180 -0
- package/opencode/agents/evaluator.md +35 -0
- package/opencode/agents/evolver.md +31 -0
- package/opencode/agents/lead.md +251 -0
- package/opencode/agents/researcher.md +76 -0
- package/opencode/agents/review_api.md +34 -0
- package/opencode/agents/review_coordinator.md +111 -0
- package/opencode/agents/review_quality.md +35 -0
- package/opencode/agents/review_security.md +35 -0
- package/opencode/agents/review_tests.md +37 -0
- package/opencode/agents/reviewer.md +116 -0
- package/opencode/agents/scoper.md +75 -0
- package/opencode/agents/specifier.md +116 -0
- package/opencode/commands/code-simplify.md +36 -0
- package/opencode/commands/design.md +27 -0
- package/opencode/commands/evolve.md +165 -0
- package/opencode/commands/feature.md +67 -0
- package/opencode/commands/implement.md +11 -0
- package/opencode/commands/init.md +34 -0
- package/opencode/commands/loop.md +145 -0
- package/opencode/commands/mvp-spec.md +20 -0
- package/opencode/commands/plan.md +74 -0
- package/opencode/commands/research.md +12 -0
- package/opencode/commands/review-orchestrated.md +47 -0
- package/opencode/commands/review-preflight.md +26 -0
- package/opencode/commands/review.md +18 -0
- package/opencode/commands/scope.md +36 -0
- package/opencode/commands/spec.md +12 -0
- package/opencode/commands/test.md +40 -0
- package/opencode/docs/ai/evolution/README.md +135 -0
- package/opencode/docs/ai/evolution/benchmarks/manual-scenarios.md +123 -0
- package/opencode/docs/ai/evolution/benchmarks/router-scenarios.jsonl +8 -0
- package/opencode/docs/ai/evolution/evolution_history.md +83 -0
- package/opencode/docs/ai/evolution/mechanisms.jsonl +7 -0
- package/opencode/docs/ai/evolution/rejected_mechanisms.jsonl +2 -0
- package/opencode/docs/ai/evolution/runs/README.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/analysis/overview.md +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_evaluation.json +108 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_manifest.json +52 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/evaluation.md +19 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/post_evaluation.md +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/analysis/overview.md +7 -0
- package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/change_evaluation.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/evaluation.md +19 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_evaluation.json +66 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_manifest.json +82 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/evaluation.md +20 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/ahe-run-lifecycle-validator.md +40 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/evolve-evaluation-only-contract.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/open-design-tool-contract.md +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/slash-command-contract-coverage.md +40 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/overview.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/pre_apply_approval.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_evaluation.json +252 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_manifest.json +210 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/evaluation.md +25 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_apply_evaluation.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_manifest_evaluation.md +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/pre_apply_evaluation.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_manifest.json +30 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/evaluation.md +25 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_manifest.json +29 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/evaluation.md +18 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_manifest.json +34 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_evaluation.json +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_manifest.json +28 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/analysis/overview.md +9 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_manifest.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/evaluation.md +18 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/analysis/overview.md +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_manifest.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/analysis/overview.md +10 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_manifest.json +30 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/analysis/overview.md +25 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_evaluation.json +28 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_manifest.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/evaluation.md +22 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/analysis/overview.md +27 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_evaluation.json +32 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_manifest.json +49 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/evaluation.md +92 -0
- package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/detail/token-vs-semantic.md +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/overview.md +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/evaluation.md +36 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_evaluation.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_manifest.json +47 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/evaluation.md +27 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/analysis/overview.md +32 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_evaluation.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_manifest.json +35 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/evaluation.md +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-1-feature-sidecar-false-positive.md +51 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-2-checker-time-budget.md +52 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/overview.md +99 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_evaluation.json +61 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_manifest.json +61 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/evaluation.md +448 -0
- package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/detail/intake-gray-zone.md +65 -0
- package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/overview.md +172 -0
- package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/evaluation.md +226 -0
- package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/detail/plan-only-gray-zone.md +62 -0
- package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/overview.md +167 -0
- package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/evaluation.md +163 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/analysis/overview.md +42 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_evaluation.json +46 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_manifest.json +57 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/evaluation.md +48 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/contract-vs-runtime-gap.md +163 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/evidence-collection-blocker.md +134 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/analysis/overview.md +111 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/change_evaluation.json +52 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/change_manifest.json +50 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/evaluation.md +46 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/manifest-justification.md +48 -0
- package/opencode/docs/ai/evolution/session-sources.md +91 -0
- package/opencode/docs/ai/harness/README.md +32 -0
- package/opencode/docs/ai/harness/agents.md +148 -0
- package/opencode/docs/ai/harness/checks.md +119 -0
- package/opencode/docs/ai/harness/commands.md +391 -0
- package/opencode/docs/ai/harness/evidence.md +85 -0
- package/opencode/docs/ai/harness/init-detection-rules.md +160 -0
- package/opencode/docs/ai/harness/orchestrated-review.md +131 -0
- package/opencode/docs/ai/harness/skill-metadata-schema.md +198 -0
- package/opencode/docs/ai/harness/skill-resolution.md +202 -0
- package/opencode/docs/ai/harness/skill_registry.json +443 -0
- package/opencode/docs/ai/harness/skill_registry.md +43 -0
- package/opencode/docs/ai/project-context-template.md +53 -0
- package/opencode/opencode.json +38 -0
- package/opencode/package-lock.json +1717 -0
- package/opencode/package.json +11 -0
- package/opencode/plugins/token-tree-usage.tsx +206 -0
- package/opencode/references/performance-checklist.md +153 -0
- package/opencode/references/security-checklist.md +134 -0
- package/opencode/references/testing-patterns.md +236 -0
- package/opencode/scripts/check-harness.mjs +1572 -0
- package/opencode/scripts/check-harness.test.mjs +820 -0
- package/opencode/scripts/collect-session-evidence.mjs +612 -0
- package/opencode/scripts/collect-session-evidence.test.mjs +443 -0
- package/opencode/scripts/preflight-audit.mjs +497 -0
- package/opencode/scripts/preflight-audit.test.mjs +363 -0
- package/opencode/scripts/project-capability-snapshot.mjs +407 -0
- package/opencode/scripts/project-capability-snapshot.test.mjs +382 -0
- package/opencode/scripts/review-orchestrated-prepare.mjs +547 -0
- package/opencode/scripts/review-orchestrated-prepare.test.mjs +516 -0
- package/opencode/scripts/skill-resolver.mjs +585 -0
- package/opencode/scripts/skill-resolver.test.mjs +781 -0
- package/opencode/scripts/update-skill-registry.mjs +380 -0
- package/opencode/skills/api-and-interface-design/SKILL.md +315 -0
- package/opencode/skills/autonomous-loops/SKILL.md +312 -0
- package/opencode/skills/code-review-and-quality/SKILL.md +365 -0
- package/opencode/skills/code-simplification/SKILL.md +345 -0
- package/opencode/skills/context-engineering/SKILL.md +252 -0
- package/opencode/skills/debugging-and-error-recovery/SKILL.md +316 -0
- package/opencode/skills/documentation-and-adrs/SKILL.md +298 -0
- package/opencode/skills/doubt-driven-development/SKILL.md +168 -0
- package/opencode/skills/iterative-retrieval/SKILL.md +232 -0
- package/opencode/skills/open-design/SKILL.md +123 -0
- package/opencode/skills/performance-optimization/SKILL.md +365 -0
- package/opencode/skills/security-and-hardening/SKILL.md +369 -0
- package/opencode/skills/source-driven-development/SKILL.md +210 -0
- package/opencode/skills/test-driven-development/SKILL.md +406 -0
- package/opencode/skills/using-agent-skills/SKILL.md +194 -0
- package/opencode/skills/verification-loop/SKILL.md +162 -0
- package/opencode/tools/open_design.ts +361 -0
- package/opencode/tui.json +5 -0
- package/package.json +20 -0
- package/rollback.sh +5 -0
- package/scripts/check.sh +184 -0
- package/scripts/install-smoke.sh +111 -0
- package/scripts/manage-installation.mjs +1498 -0
- package/scripts/manage-installation.test.mjs +1936 -0
- package/scripts/version.mjs +197 -0
- package/scripts/version.test.mjs +195 -0
- package/uninstall.sh +5 -0
- package/upgrade.sh +5 -0
|
@@ -0,0 +1,1936 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { Readable } from "node:stream";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import test from "node:test";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
assertSafeTarget,
|
|
13
|
+
buildPlan,
|
|
14
|
+
canonicalManifestBytes,
|
|
15
|
+
createInstallationManager,
|
|
16
|
+
inventorySource,
|
|
17
|
+
inspectInstallation,
|
|
18
|
+
main,
|
|
19
|
+
normalizeManagedPath,
|
|
20
|
+
parseCliArgs,
|
|
21
|
+
resolveTarget,
|
|
22
|
+
validateManifest,
|
|
23
|
+
validateTransaction,
|
|
24
|
+
} from "./manage-installation.mjs";
|
|
25
|
+
|
|
26
|
+
function makeFixture(t) {
|
|
27
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "oak-manager-test-"));
|
|
28
|
+
const sourceRoot = path.join(root, "repo", "opencode");
|
|
29
|
+
const targetRoot = path.join(root, "target");
|
|
30
|
+
fs.mkdirSync(sourceRoot, { recursive: true });
|
|
31
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
32
|
+
return { root, sourceRoot, targetRoot };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function deterministicDeps(overrides = {}) {
|
|
36
|
+
return {
|
|
37
|
+
clock: () => new Date("2026-07-20T00:00:00.000Z"),
|
|
38
|
+
transactionId: () => "tx-0001",
|
|
39
|
+
pidProbe: () => ({ alive: false, code: "ESRCH" }),
|
|
40
|
+
failpoint: () => {},
|
|
41
|
+
...overrides,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function capture() {
|
|
46
|
+
let value = "";
|
|
47
|
+
return {
|
|
48
|
+
stream: { write(chunk) { value += String(chunk); return true; } },
|
|
49
|
+
read: () => value,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const HASH_A = "a".repeat(64);
|
|
54
|
+
const HASH_B = "b".repeat(64);
|
|
55
|
+
const REPOSITORY_ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
56
|
+
|
|
57
|
+
function validManifest(overrides = {}) {
|
|
58
|
+
return {
|
|
59
|
+
schema_version: 1,
|
|
60
|
+
manager: "opencode-agent-orchestration-kit",
|
|
61
|
+
kit_version: "1.0.27",
|
|
62
|
+
payload_sha256: HASH_A,
|
|
63
|
+
created_at: "2026-07-20T00:00:00.000Z",
|
|
64
|
+
updated_at: "2026-07-20T00:00:00.000Z",
|
|
65
|
+
last_transaction_id: "tx-0001",
|
|
66
|
+
owned_files: [{ path: "agents/lead.md", sha256: HASH_A, mode: 0o644 }],
|
|
67
|
+
preserved_files: [{
|
|
68
|
+
path: "opencode.json",
|
|
69
|
+
observed_sha256: HASH_A,
|
|
70
|
+
observed_mode: 0o600,
|
|
71
|
+
source_sha256: HASH_B,
|
|
72
|
+
source_mode: 0o644,
|
|
73
|
+
reason: "preexisting-user-file",
|
|
74
|
+
merge_acknowledgement: null,
|
|
75
|
+
}],
|
|
76
|
+
...overrides,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function manifestDigest(manifest) {
|
|
81
|
+
return crypto.createHash("sha256").update(canonicalManifestBytes(manifest)).digest("hex");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function validTransaction({ command = "install", operation = null } = {}) {
|
|
85
|
+
const previous = command === "install" ? null : validManifest();
|
|
86
|
+
const next = command === "uninstall" ? null : validManifest();
|
|
87
|
+
const operations = operation ? [{ index: 0, ...operation }] : [];
|
|
88
|
+
return {
|
|
89
|
+
schema_version: 1,
|
|
90
|
+
transaction_id: "tx-0001",
|
|
91
|
+
command,
|
|
92
|
+
status: "planned",
|
|
93
|
+
rollback_origin: "none",
|
|
94
|
+
created_at: "2026-07-20T00:00:00.000Z",
|
|
95
|
+
source_payload_sha256: HASH_A,
|
|
96
|
+
previous_manifest: previous,
|
|
97
|
+
next_manifest: next,
|
|
98
|
+
previous_manifest_sha256: previous ? manifestDigest(previous) : null,
|
|
99
|
+
next_manifest_sha256: next ? manifestDigest(next) : null,
|
|
100
|
+
lock: {
|
|
101
|
+
transaction_id: "tx-0001",
|
|
102
|
+
pid: 1234,
|
|
103
|
+
command,
|
|
104
|
+
created_at: "2026-07-20T00:00:00.000Z",
|
|
105
|
+
},
|
|
106
|
+
operations,
|
|
107
|
+
completed_operation_indexes: [],
|
|
108
|
+
rollback_completed_operation_indexes: [],
|
|
109
|
+
manifest_write_completed: false,
|
|
110
|
+
rollback_manifest_write_completed: false,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function validAcknowledgementTransaction() {
|
|
115
|
+
const transaction = validTransaction({ command: "accept-preserved" });
|
|
116
|
+
const next = structuredClone(transaction.next_manifest);
|
|
117
|
+
const entry = next.preserved_files[0];
|
|
118
|
+
entry.observed_sha256 = HASH_A;
|
|
119
|
+
entry.observed_mode = 0o600;
|
|
120
|
+
entry.source_sha256 = HASH_B;
|
|
121
|
+
entry.source_mode = 0o644;
|
|
122
|
+
entry.merge_acknowledgement = {
|
|
123
|
+
target_sha256: HASH_A,
|
|
124
|
+
target_mode: 0o600,
|
|
125
|
+
source_sha256: HASH_B,
|
|
126
|
+
source_mode: 0o644,
|
|
127
|
+
acknowledged_at: "2026-07-20T00:00:00.000Z",
|
|
128
|
+
};
|
|
129
|
+
transaction.next_manifest = next;
|
|
130
|
+
transaction.next_manifest_sha256 = manifestDigest(next);
|
|
131
|
+
return transaction;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function put(root, relative, bytes, mode = 0o644) {
|
|
135
|
+
const fullPath = path.join(root, relative);
|
|
136
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
137
|
+
fs.writeFileSync(fullPath, bytes);
|
|
138
|
+
fs.chmodSync(fullPath, mode);
|
|
139
|
+
return {
|
|
140
|
+
path: relative,
|
|
141
|
+
sha256: crypto.createHash("sha256").update(bytes).digest("hex"),
|
|
142
|
+
mode,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function persistManifest(targetRoot, manifest) {
|
|
147
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true, mode: 0o700 });
|
|
148
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "manifest.json"), canonicalManifestBytes(manifest), { mode: 0o600 });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function planFixture(command, sourceRoot, targetRoot, options = {}) {
|
|
152
|
+
const inspection = inspectInstallation({ sourceRoot, targetRoot });
|
|
153
|
+
return buildPlan({
|
|
154
|
+
command,
|
|
155
|
+
inspection,
|
|
156
|
+
options: {
|
|
157
|
+
clock: () => new Date("2026-07-20T00:00:00.000Z"),
|
|
158
|
+
transactionId: "tx-plan",
|
|
159
|
+
kitVersion: command === "upgrade" ? "1.0.28" : "1.0.27",
|
|
160
|
+
...options,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function managerFixture(sourceRoot, overrides = {}) {
|
|
166
|
+
return createInstallationManager({
|
|
167
|
+
sourceRoot,
|
|
168
|
+
versionProvider: () => "1.0.27",
|
|
169
|
+
...deterministicDeps(),
|
|
170
|
+
...overrides,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
test("[S020] CLI parsing, help, target precedence, and exit codes are deterministic", async (t) => {
|
|
175
|
+
await t.test("explicit target wins without tilde expansion", () => {
|
|
176
|
+
const parsed = parseCliArgs("install", ["--dry-run", "--target", "~/oak"]);
|
|
177
|
+
assert.equal(parsed.dryRun, true);
|
|
178
|
+
assert.equal(resolveTarget(parsed, { OPENCODE_CONFIG_DIR: "/env", HOME: "/home" }), "~/oak");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
await t.test("environment target wins over HOME", () => {
|
|
182
|
+
assert.equal(resolveTarget(parseCliArgs("doctor", []), {
|
|
183
|
+
OPENCODE_CONFIG_DIR: "/env/config",
|
|
184
|
+
HOME: "/home/user",
|
|
185
|
+
}), "/env/config");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
await t.test("HOME fallback is deterministic", () => {
|
|
189
|
+
assert.equal(resolveTarget(parseCliArgs("rollback", []), { HOME: "/home/user" }), "/home/user/.config/opencode");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await t.test("empty configured target and missing HOME fail", () => {
|
|
193
|
+
assert.throws(() => resolveTarget(parseCliArgs("install", []), {
|
|
194
|
+
OPENCODE_CONFIG_DIR: "",
|
|
195
|
+
HOME: "/home/user",
|
|
196
|
+
}), /OPENCODE_CONFIG_DIR must not be empty/);
|
|
197
|
+
assert.throws(() => resolveTarget(parseCliArgs("install", []), {}), /HOME is required/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
await t.test("command-specific flags are strict", () => {
|
|
201
|
+
assert.equal(parseCliArgs("install", ["--force"]).force, true);
|
|
202
|
+
assert.equal(parseCliArgs("uninstall", ["--yes"]).yes, true);
|
|
203
|
+
assert.equal(parseCliArgs("doctor", ["--accept-preserved", "opencode.json"]).acceptPreserved, "opencode.json");
|
|
204
|
+
assert.throws(() => parseCliArgs("upgrade", ["--force"]), /not valid for upgrade/);
|
|
205
|
+
assert.throws(() => parseCliArgs("install", ["--yes"]), /not valid for install/);
|
|
206
|
+
assert.throws(() => parseCliArgs("doctor", ["--target"]), /--target requires a path/);
|
|
207
|
+
assert.throws(() => parseCliArgs("doctor", ["--wat"]), /Unknown argument/);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await t.test("help returns zero and invalid invocation returns two", async () => {
|
|
211
|
+
const stdout = capture();
|
|
212
|
+
const stderr = capture();
|
|
213
|
+
assert.equal(await main(["install", "--help"], { stdout: stdout.stream, stderr: stderr.stream }), 0);
|
|
214
|
+
assert.match(stdout.read(), /^Usage: \.\/install\.sh/);
|
|
215
|
+
assert.equal(stderr.read(), "");
|
|
216
|
+
|
|
217
|
+
const invalidError = capture();
|
|
218
|
+
assert.equal(await main(["upgrade", "--force"], { stdout: capture().stream, stderr: invalidError.stream }), 2);
|
|
219
|
+
assert.match(invalidError.read(), /not valid for upgrade/);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await t.test("all public wrappers are thin and propagate deterministic CLI exits", () => {
|
|
223
|
+
const usages = {
|
|
224
|
+
install: "Usage: ./install.sh [--dry-run] [--force] [--target PATH]",
|
|
225
|
+
upgrade: "Usage: ./upgrade.sh [--dry-run] [--target PATH]",
|
|
226
|
+
doctor: "Usage: ./doctor.sh [--accept-preserved PATH] [--target PATH]",
|
|
227
|
+
uninstall: "Usage: ./uninstall.sh [--dry-run] [--yes] [--target PATH]",
|
|
228
|
+
rollback: "Usage: ./rollback.sh [--dry-run] [--target PATH]",
|
|
229
|
+
};
|
|
230
|
+
for (const [command, usage] of Object.entries(usages)) {
|
|
231
|
+
const wrapper = path.join(REPOSITORY_ROOT, `${command}.sh`);
|
|
232
|
+
const help = spawnSync(wrapper, ["--help"], { cwd: REPOSITORY_ROOT, encoding: "utf8" });
|
|
233
|
+
assert.equal(help.status, 0, `${command} help`);
|
|
234
|
+
assert.equal(help.stdout.trim(), usage);
|
|
235
|
+
const invalid = spawnSync(wrapper, ["--unknown"], { cwd: REPOSITORY_ROOT, encoding: "utf8" });
|
|
236
|
+
assert.equal(invalid.status, 2, `${command} invalid exit`);
|
|
237
|
+
const body = fs.readFileSync(wrapper, "utf8");
|
|
238
|
+
assert.match(body, new RegExp(`manage-installation\\.mjs" ${command} "\\$@"`));
|
|
239
|
+
assert.equal(body.includes("manifest.json"), false);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("[S019] source symlinks are rejected without being followed", (t) => {
|
|
245
|
+
const { sourceRoot } = makeFixture(t);
|
|
246
|
+
fs.writeFileSync(path.join(sourceRoot, "real.md"), "safe");
|
|
247
|
+
fs.symlinkSync("real.md", path.join(sourceRoot, "linked.md"));
|
|
248
|
+
assert.throws(() => inventorySource(sourceRoot), /symlink.*linked\.md/i);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("[S033] source inventory is sorted and preserves executable modes", (t) => {
|
|
252
|
+
const { sourceRoot } = makeFixture(t);
|
|
253
|
+
fs.mkdirSync(path.join(sourceRoot, "scripts"));
|
|
254
|
+
fs.writeFileSync(path.join(sourceRoot, "z.md"), "z");
|
|
255
|
+
fs.writeFileSync(path.join(sourceRoot, "scripts", "run.sh"), "#!/bin/sh\n");
|
|
256
|
+
fs.mkdirSync(path.join(sourceRoot, "node_modules", ".bin"), { recursive: true });
|
|
257
|
+
fs.writeFileSync(path.join(sourceRoot, "node_modules", "package.js"), "ignored");
|
|
258
|
+
fs.symlinkSync("../package.js", path.join(sourceRoot, "node_modules", ".bin", "package"));
|
|
259
|
+
fs.chmodSync(path.join(sourceRoot, "z.md"), 0o640);
|
|
260
|
+
fs.chmodSync(path.join(sourceRoot, "scripts", "run.sh"), 0o751);
|
|
261
|
+
|
|
262
|
+
const inventory = inventorySource(sourceRoot);
|
|
263
|
+
assert.deepEqual(inventory.entries.map((entry) => [entry.path, entry.mode]), [
|
|
264
|
+
["scripts/run.sh", 0o751],
|
|
265
|
+
["z.md", 0o640],
|
|
266
|
+
]);
|
|
267
|
+
assert.match(inventory.entries[0].sha256, /^[0-9a-f]{64}$/);
|
|
268
|
+
assert.match(inventory.payloadSha256, /^[0-9a-f]{64}$/);
|
|
269
|
+
assert.equal(inventory.entries.some((entry) => entry.path.startsWith("node_modules/")), false);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("[S061] every source payload entry under the reserved .oak namespace is rejected", (t) => {
|
|
273
|
+
const { sourceRoot } = makeFixture(t);
|
|
274
|
+
fs.mkdirSync(path.join(sourceRoot, ".oak"));
|
|
275
|
+
fs.writeFileSync(path.join(sourceRoot, ".oak", "manifest.json"), "{}");
|
|
276
|
+
assert.throws(() => inventorySource(sourceRoot), /reserved.*\.oak/i);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("[S063] target equal to repository root is rejected", (t) => {
|
|
280
|
+
const { root, sourceRoot } = makeFixture(t);
|
|
281
|
+
const repositoryRoot = path.dirname(sourceRoot);
|
|
282
|
+
assert.throws(() => assertSafeTarget({ targetRoot: repositoryRoot, repositoryRoot, sourceRoot }), /repository/i);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("[S064] target ancestor of repository root is rejected", (t) => {
|
|
286
|
+
const { root, sourceRoot } = makeFixture(t);
|
|
287
|
+
assert.throws(() => assertSafeTarget({ targetRoot: root, repositoryRoot: path.dirname(sourceRoot), sourceRoot }), /repository/i);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("[S065] target descendant of repository root is rejected", (t) => {
|
|
291
|
+
const { sourceRoot } = makeFixture(t);
|
|
292
|
+
const repositoryRoot = path.dirname(sourceRoot);
|
|
293
|
+
assert.throws(() => assertSafeTarget({ targetRoot: path.join(repositoryRoot, "target"), repositoryRoot, sourceRoot }), /repository/i);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("[S066] target related to source payload is rejected", (t) => {
|
|
297
|
+
const { sourceRoot } = makeFixture(t);
|
|
298
|
+
const repositoryRoot = path.dirname(sourceRoot);
|
|
299
|
+
assert.throws(() => assertSafeTarget({ targetRoot: path.join(sourceRoot, "nested"), repositoryRoot, sourceRoot }), /source payload/i);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("[S067] normalization cannot hide a dangerous target relationship", (t) => {
|
|
303
|
+
const { sourceRoot } = makeFixture(t);
|
|
304
|
+
const repositoryRoot = path.dirname(sourceRoot);
|
|
305
|
+
const disguised = path.join(repositoryRoot, "outside", "..", "opencode", "nested");
|
|
306
|
+
assert.throws(() => assertSafeTarget({ targetRoot: disguised, repositoryRoot, sourceRoot }), /source payload/i);
|
|
307
|
+
assert.throws(() => normalizeManagedPath("agents/../secrets.md"), /normalized/i);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("[S014] manifest validation rejects malformed and ambiguous ownership state", () => {
|
|
311
|
+
assert.throws(() => validateManifest({}), /manifest/);
|
|
312
|
+
assert.throws(() => validateManifest(validManifest({ schema_version: 2 })), /schema_version/);
|
|
313
|
+
assert.throws(() => validateManifest(validManifest({ owned_files: [
|
|
314
|
+
{ path: "agents/lead.md", sha256: HASH_A, mode: 0o644 },
|
|
315
|
+
{ path: "agents/lead.md", sha256: HASH_A, mode: 0o644 },
|
|
316
|
+
] })), /duplicate/i);
|
|
317
|
+
assert.throws(() => validateManifest(validManifest({ owned_files: [
|
|
318
|
+
{ path: "z.md", sha256: HASH_A, mode: 0o644 },
|
|
319
|
+
{ path: "a.md", sha256: HASH_A, mode: 0o644 },
|
|
320
|
+
] })), /sorted/i);
|
|
321
|
+
assert.throws(() => validateManifest(validManifest({ owned_files: [
|
|
322
|
+
{ path: "opencode.json", sha256: HASH_A, mode: 0o644 },
|
|
323
|
+
] })), /overlap/i);
|
|
324
|
+
assert.throws(() => validateManifest({ ...validManifest(), extra: true }), /unknown field/i);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("[S046] persisted modes outside 0000 through 0777 fail closed", () => {
|
|
328
|
+
assert.throws(() => validateManifest(validManifest({ owned_files: [
|
|
329
|
+
{ path: "agents/lead.md", sha256: HASH_A, mode: 0o1000 },
|
|
330
|
+
] })), /mode/i);
|
|
331
|
+
assert.throws(() => validateManifest(validManifest({ owned_files: [
|
|
332
|
+
{ path: "agents/lead.md", sha256: HASH_A, mode: 420.5 },
|
|
333
|
+
] })), /mode/i);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("[S062] manifest ownership cannot include the reserved .oak namespace", () => {
|
|
337
|
+
assert.throws(() => validateManifest(validManifest({ owned_files: [
|
|
338
|
+
{ path: ".oak/manifest.json", sha256: HASH_A, mode: 0o600 },
|
|
339
|
+
] })), /reserved.*\.oak/i);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("[S124] partial merge acknowledgement fails manifest validation", () => {
|
|
343
|
+
const manifest = validManifest();
|
|
344
|
+
manifest.preserved_files[0].merge_acknowledgement = { target_sha256: HASH_A };
|
|
345
|
+
assert.throws(() => validateManifest(manifest), /merge_acknowledgement/i);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("[S125] accept-preserved rejects acknowledgement tuples that differ from next baselines", () => {
|
|
349
|
+
const transaction = validAcknowledgementTransaction();
|
|
350
|
+
transaction.next_manifest.preserved_files[0].merge_acknowledgement.target_mode = 0o644;
|
|
351
|
+
transaction.next_manifest_sha256 = manifestDigest(transaction.next_manifest);
|
|
352
|
+
assert.throws(() => validateTransaction(transaction), /acknowledgement.*baseline/i);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test("[S128] canonical manifest bytes are stable, sorted, and newline terminated", () => {
|
|
356
|
+
const manifest = validManifest();
|
|
357
|
+
validateManifest(manifest);
|
|
358
|
+
const first = canonicalManifestBytes(manifest);
|
|
359
|
+
const second = canonicalManifestBytes(structuredClone(manifest));
|
|
360
|
+
assert.deepEqual(first, second);
|
|
361
|
+
assert.equal(first.at(-1), 0x0a);
|
|
362
|
+
assert.equal(first.includes(Buffer.from("\n ")), false);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("[S072] adopt is forbidden in transaction operations", () => {
|
|
366
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
367
|
+
kind: "adopt", path: "agents/a.md", before_sha256: null, before_mode: null,
|
|
368
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: null,
|
|
369
|
+
} })), /operation kind/i);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("[S073] preserve is forbidden in transaction operations", () => {
|
|
373
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
374
|
+
kind: "preserve", path: "agents/a.md", before_sha256: null, before_mode: null,
|
|
375
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: null,
|
|
376
|
+
} })), /operation kind/i);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test("[S074] add cannot carry a backup", () => {
|
|
380
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
381
|
+
kind: "add", path: "agents/a.md", before_sha256: null, before_mode: null,
|
|
382
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: "files/000000",
|
|
383
|
+
} })), /add.*backup/i);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test("[S075] update requires a valid backup", () => {
|
|
387
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
388
|
+
kind: "update", path: "agents/a.md", before_sha256: HASH_B, before_mode: 0o600,
|
|
389
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: null,
|
|
390
|
+
} })), /update.*backup/i);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test("[S076] remove requires a valid backup", () => {
|
|
394
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
395
|
+
kind: "remove", path: "agents/a.md", before_sha256: HASH_B, before_mode: 0o600,
|
|
396
|
+
after_sha256: null, after_mode: null, backup_path: null,
|
|
397
|
+
} })), /remove.*backup/i);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test("[S085] add requires an absent before-state", () => {
|
|
401
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
402
|
+
kind: "add", path: "agents/a.md", before_sha256: HASH_B, before_mode: 0o600,
|
|
403
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: null,
|
|
404
|
+
} })), /add.*before/i);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("[S086] remove requires an absent after-state", () => {
|
|
408
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
409
|
+
kind: "remove", path: "agents/a.md", before_sha256: HASH_B, before_mode: 0o600,
|
|
410
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: "files/000000",
|
|
411
|
+
} })), /remove.*after/i);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("[S087] update requires complete before and after pairs", () => {
|
|
415
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
416
|
+
kind: "update", path: "agents/a.md", before_sha256: HASH_B, before_mode: null,
|
|
417
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: "files/000000",
|
|
418
|
+
} })), /hash and mode/i);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test("[S088] every operation hash and mode form an inseparable pair", () => {
|
|
422
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
423
|
+
kind: "add", path: "agents/a.md", before_sha256: null, before_mode: null,
|
|
424
|
+
after_sha256: HASH_A, after_mode: null, backup_path: null,
|
|
425
|
+
} })), /hash and mode/i);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test("[S089] unknown journal operation kinds fail closed", () => {
|
|
429
|
+
assert.throws(() => validateTransaction(validTransaction({ operation: {
|
|
430
|
+
kind: "copy", path: "agents/a.md", before_sha256: null, before_mode: null,
|
|
431
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: null,
|
|
432
|
+
} })), /operation kind/i);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test("[S095] install transaction requires null previous and complete next manifest", () => {
|
|
436
|
+
assert.doesNotThrow(() => validateTransaction(validTransaction({ command: "install" })));
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
test("[S096] uninstall transaction requires complete previous and null next manifest", () => {
|
|
440
|
+
assert.doesNotThrow(() => validateTransaction(validTransaction({ command: "uninstall" })));
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
test("[S097] manifest objects cannot be paired with null digests", () => {
|
|
444
|
+
const transaction = validTransaction({ command: "upgrade" });
|
|
445
|
+
transaction.previous_manifest_sha256 = null;
|
|
446
|
+
assert.throws(() => validateTransaction(transaction), /previous_manifest_sha256/i);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test("[S098] null manifests cannot be paired with non-null digests", () => {
|
|
450
|
+
const transaction = validTransaction({ command: "install" });
|
|
451
|
+
transaction.previous_manifest_sha256 = HASH_A;
|
|
452
|
+
assert.throws(() => validateTransaction(transaction), /previous_manifest_sha256/i);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test("[S129] an empty object never represents an absent manifest", () => {
|
|
456
|
+
const transaction = validTransaction({ command: "install" });
|
|
457
|
+
transaction.previous_manifest = {};
|
|
458
|
+
assert.throws(() => validateTransaction(transaction), /previous_manifest/i);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("[S130] both transaction manifests cannot be null", () => {
|
|
462
|
+
const transaction = validTransaction({ command: "uninstall" });
|
|
463
|
+
transaction.previous_manifest = null;
|
|
464
|
+
transaction.previous_manifest_sha256 = null;
|
|
465
|
+
assert.throws(() => validateTransaction(transaction), /presence/i);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test("[S134] upgrade accepts only two complete matching manifests", () => {
|
|
469
|
+
assert.doesNotThrow(() => validateTransaction(validTransaction({ command: "upgrade" })));
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
test("[S135] accept-preserved accepts valid complete matching manifests", () => {
|
|
473
|
+
assert.doesNotThrow(() => validateTransaction(validAcknowledgementTransaction()));
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
test("[S136] every transaction command rejects undeclared manifest presence pairs", () => {
|
|
477
|
+
for (const command of ["install", "upgrade", "accept-preserved", "uninstall"]) {
|
|
478
|
+
const transaction = validTransaction({ command });
|
|
479
|
+
transaction.previous_manifest = null;
|
|
480
|
+
transaction.previous_manifest_sha256 = null;
|
|
481
|
+
transaction.next_manifest = null;
|
|
482
|
+
transaction.next_manifest_sha256 = null;
|
|
483
|
+
assert.throws(() => validateTransaction(transaction), /presence/i);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test("[S003] initial install preserves differing protected configuration", (t) => {
|
|
488
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
489
|
+
put(sourceRoot, "opencode.json", "source\n");
|
|
490
|
+
const user = put(targetRoot, "opencode.json", "user\n", 0o600);
|
|
491
|
+
const plan = planFixture("install", sourceRoot, targetRoot);
|
|
492
|
+
assert.equal(plan.blockers.length, 0);
|
|
493
|
+
assert.deepEqual(plan.entries.map(({ kind, path: entryPath }) => [kind, entryPath]), [["preserve", "opencode.json"]]);
|
|
494
|
+
assert.equal(plan.nextManifest.preserved_files[0].observed_sha256, user.sha256);
|
|
495
|
+
assert.equal(plan.nextManifest.preserved_files[0].reason, "preexisting-user-file");
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
test("[S004] arbitrary unrelated target files and directory modes remain untouched", async (t) => {
|
|
499
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
500
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
501
|
+
put(targetRoot, "notes/private.txt", "mine\n");
|
|
502
|
+
fs.chmodSync(targetRoot, 0o750);
|
|
503
|
+
const plan = planFixture("install", sourceRoot, targetRoot);
|
|
504
|
+
assert.equal(plan.entries.some((entry) => entry.path === "notes/private.txt"), false);
|
|
505
|
+
assert.equal((await managerFixture(sourceRoot).run("install", { targetRoot })).exitCode, 0);
|
|
506
|
+
assert.equal(fs.statSync(targetRoot).mode & 0o777, 0o750);
|
|
507
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "notes/private.txt"), "utf8"), "mine\n");
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
test("[S005] an unowned differing managed collision blocks the whole install", (t) => {
|
|
511
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
512
|
+
put(sourceRoot, "agents/lead.md", "source\n");
|
|
513
|
+
put(targetRoot, "agents/lead.md", "user\n");
|
|
514
|
+
const before = fs.readFileSync(path.join(targetRoot, "agents/lead.md"));
|
|
515
|
+
const plan = planFixture("install", sourceRoot, targetRoot);
|
|
516
|
+
assert.deepEqual(plan.blockers.map((entry) => entry.classification), ["unowned-conflict"]);
|
|
517
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, "agents/lead.md")), before);
|
|
518
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak")), false);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test("[S007] exact initial matches are adopted without a file operation", (t) => {
|
|
522
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
523
|
+
const existing = put(targetRoot, "agents/lead.md", "same\n", 0o640);
|
|
524
|
+
put(sourceRoot, "agents/lead.md", "same\n", 0o640);
|
|
525
|
+
const plan = planFixture("install", sourceRoot, targetRoot);
|
|
526
|
+
assert.equal(plan.entries[0].kind, "adopt");
|
|
527
|
+
assert.deepEqual(plan.operations, []);
|
|
528
|
+
assert.deepEqual(plan.nextManifest.owned_files, [existing]);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test("[S008] upgrade plans sorted add, update, and remove operations", (t) => {
|
|
532
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
533
|
+
const oldUpdate = put(targetRoot, "agents/update.md", "old\n");
|
|
534
|
+
const oldRemove = put(targetRoot, "agents/remove.md", "remove\n");
|
|
535
|
+
const newUpdate = put(sourceRoot, "agents/update.md", "new\n");
|
|
536
|
+
const newAdd = put(sourceRoot, "agents/add.md", "add\n");
|
|
537
|
+
persistManifest(targetRoot, validManifest({
|
|
538
|
+
payload_sha256: HASH_A,
|
|
539
|
+
owned_files: [oldRemove, oldUpdate],
|
|
540
|
+
preserved_files: [],
|
|
541
|
+
}));
|
|
542
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
543
|
+
assert.equal(plan.blockers.length, 0);
|
|
544
|
+
assert.deepEqual(plan.operations.map(({ kind, path: entryPath }) => [kind, entryPath]), [
|
|
545
|
+
["add", newAdd.path],
|
|
546
|
+
["remove", oldRemove.path],
|
|
547
|
+
["update", newUpdate.path],
|
|
548
|
+
]);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
test("[S009] modified owned files block every otherwise-safe upgrade operation", (t) => {
|
|
552
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
553
|
+
const installed = put(targetRoot, "agents/lead.md", "installed\n");
|
|
554
|
+
persistManifest(targetRoot, validManifest({ owned_files: [installed], preserved_files: [] }));
|
|
555
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
556
|
+
put(sourceRoot, "agents/other.md", "other\n");
|
|
557
|
+
fs.writeFileSync(path.join(targetRoot, "agents/lead.md"), "user edit\n");
|
|
558
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
559
|
+
assert.deepEqual(plan.blockers.map((entry) => entry.classification), ["owned-modified"]);
|
|
560
|
+
assert.equal(plan.canApply, false);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
test("[S010] modified obsolete owned files block upgrade", (t) => {
|
|
564
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
565
|
+
const installed = put(targetRoot, "agents/old.md", "installed\n");
|
|
566
|
+
persistManifest(targetRoot, validManifest({ owned_files: [installed], preserved_files: [] }));
|
|
567
|
+
fs.writeFileSync(path.join(targetRoot, "agents/old.md"), "user edit\n");
|
|
568
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
569
|
+
assert.deepEqual(plan.blockers.map((entry) => entry.classification), ["obsolete-modified"]);
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test("[S024] upgrade leaves an exact pre-existing new path user-owned", (t) => {
|
|
573
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
574
|
+
const exact = put(sourceRoot, "agents/new.md", "same\n");
|
|
575
|
+
put(targetRoot, "agents/new.md", "same\n");
|
|
576
|
+
persistManifest(targetRoot, validManifest({ owned_files: [], preserved_files: [] }));
|
|
577
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
578
|
+
assert.equal(plan.entries[0].kind, "preserve");
|
|
579
|
+
assert.equal(plan.nextManifest.preserved_files[0].reason, "preexisting-exact-match");
|
|
580
|
+
assert.equal(plan.nextManifest.preserved_files[0].source_sha256, exact.sha256);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test("[S001] clean install dry-run performs zero writes", async (t) => {
|
|
584
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
585
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
586
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot, dryRun: true });
|
|
587
|
+
assert.equal(result.exitCode, 0);
|
|
588
|
+
assert.equal(result.plan.operations.length, 1);
|
|
589
|
+
assert.equal(fs.existsSync(targetRoot), false);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test("[V012] initial install persists kit version in active and rollback manifests", async (t) => {
|
|
593
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
594
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
595
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
596
|
+
assert.equal(result.exitCode, 0);
|
|
597
|
+
const active = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
598
|
+
const rollback = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json"), "utf8"));
|
|
599
|
+
assert.equal(active.kit_version, "1.0.27");
|
|
600
|
+
assert.equal(rollback.next_manifest.kit_version, "1.0.27");
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test("[V013] install dry-run reports kit version and leaves target absent", async (t) => {
|
|
604
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
605
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
606
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot, dryRun: true });
|
|
607
|
+
assert.equal(result.exitCode, 0);
|
|
608
|
+
assert.equal(result.plan.nextManifest.kit_version, "1.0.27");
|
|
609
|
+
assert.equal(fs.existsSync(targetRoot), false);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test("[V014] manifest kit version is required and canonical", () => {
|
|
613
|
+
const missing = validManifest();
|
|
614
|
+
delete missing.kit_version;
|
|
615
|
+
assert.throws(() => validateManifest(missing), /kit_version/i);
|
|
616
|
+
for (const kitVersion of ["v1.0.27", "01.0.27", "1.0.27-rc.1", "1.0"]) {
|
|
617
|
+
assert.throws(() => validateManifest(validManifest({ kit_version: kitVersion })), /version/i);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
test("[V015] manifest digest includes kit version", () => {
|
|
622
|
+
assert.notEqual(
|
|
623
|
+
manifestDigest(validManifest({ kit_version: "1.0.26" })),
|
|
624
|
+
manifestDigest(validManifest({ kit_version: "1.0.27" })),
|
|
625
|
+
);
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
test("[V016] a newer source version commits a manifest-only upgrade", async (t) => {
|
|
629
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
630
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
631
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.26" }).run("install", { targetRoot });
|
|
632
|
+
|
|
633
|
+
const result = await managerFixture(sourceRoot).run("upgrade", { targetRoot });
|
|
634
|
+
|
|
635
|
+
assert.equal(result.exitCode, 0);
|
|
636
|
+
assert.deepEqual(result.transaction.operations, []);
|
|
637
|
+
assert.equal(result.plan.hasWork, true);
|
|
638
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
639
|
+
assert.equal(manifest.kit_version, "1.0.27");
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
test("[V017] equal version and payload is a no-op", async (t) => {
|
|
643
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
644
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
645
|
+
const manager = managerFixture(sourceRoot);
|
|
646
|
+
await manager.run("install", { targetRoot });
|
|
647
|
+
const before = fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
648
|
+
|
|
649
|
+
const result = await manager.run("upgrade", { targetRoot });
|
|
650
|
+
|
|
651
|
+
assert.equal(result.exitCode, 0);
|
|
652
|
+
assert.equal(result.plan.hasWork, false);
|
|
653
|
+
assert.equal(result.transaction, undefined);
|
|
654
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json")), before);
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
test("[V018] equal version with different payload blocks before writes", async (t) => {
|
|
658
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
659
|
+
put(sourceRoot, "agents/lead.md", "old\n");
|
|
660
|
+
const manager = managerFixture(sourceRoot);
|
|
661
|
+
await manager.run("install", { targetRoot });
|
|
662
|
+
const manifestPath = path.join(targetRoot, ".oak", "manifest.json");
|
|
663
|
+
const rollbackPath = path.join(targetRoot, ".oak", "rollback", "transaction.json");
|
|
664
|
+
const beforeManifest = fs.readFileSync(manifestPath);
|
|
665
|
+
const beforeRollback = fs.readFileSync(rollbackPath);
|
|
666
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
667
|
+
|
|
668
|
+
const result = await manager.run("upgrade", { targetRoot });
|
|
669
|
+
|
|
670
|
+
assert.equal(result.exitCode, 1);
|
|
671
|
+
assert.deepEqual(result.plan.blockers.map((entry) => entry.classification), ["same-version-different-payload"]);
|
|
672
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "old\n");
|
|
673
|
+
assert.deepEqual(fs.readFileSync(manifestPath), beforeManifest);
|
|
674
|
+
assert.deepEqual(fs.readFileSync(rollbackPath), beforeRollback);
|
|
675
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "lock.json")), false);
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
test("[V019] an older source version blocks before writes", async (t) => {
|
|
679
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
680
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
681
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
682
|
+
const manifestPath = path.join(targetRoot, ".oak", "manifest.json");
|
|
683
|
+
const before = fs.readFileSync(manifestPath);
|
|
684
|
+
|
|
685
|
+
const result = await managerFixture(sourceRoot, { versionProvider: () => "1.0.26" }).run("upgrade", { targetRoot });
|
|
686
|
+
|
|
687
|
+
assert.equal(result.exitCode, 1);
|
|
688
|
+
assert.deepEqual(result.plan.blockers.map((entry) => entry.classification), ["source-older"]);
|
|
689
|
+
assert.deepEqual(fs.readFileSync(manifestPath), before);
|
|
690
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "lock.json")), false);
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
test("[V021] doctor reports deterministic version states with additive safe fields", async (t) => {
|
|
694
|
+
const cases = [
|
|
695
|
+
{ name: "current", installed: "1.0.27", source: "1.0.27", mutateSource: false, exitCode: 0 },
|
|
696
|
+
{ name: "upgrade-available", installed: "1.0.26", source: "1.0.27", mutateSource: false, exitCode: 1 },
|
|
697
|
+
{ name: "source-older", installed: "1.0.27", source: "1.0.26", mutateSource: false, exitCode: 1 },
|
|
698
|
+
{ name: "same-version-different-payload", installed: "1.0.27", source: "1.0.27", mutateSource: true, exitCode: 1 },
|
|
699
|
+
];
|
|
700
|
+
for (const scenario of cases) {
|
|
701
|
+
await t.test(scenario.name, async (child) => {
|
|
702
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
703
|
+
put(sourceRoot, "agents/lead.md", "old\n");
|
|
704
|
+
await managerFixture(sourceRoot, { versionProvider: () => scenario.installed }).run("install", { targetRoot });
|
|
705
|
+
if (scenario.mutateSource) put(sourceRoot, "agents/lead.md", "new\n");
|
|
706
|
+
|
|
707
|
+
const result = await managerFixture(sourceRoot, { versionProvider: () => scenario.source }).run("doctor", { targetRoot });
|
|
708
|
+
|
|
709
|
+
assert.equal(result.exitCode, scenario.exitCode);
|
|
710
|
+
assert.equal(result.report.sourceVersion, scenario.source);
|
|
711
|
+
assert.equal(result.report.installedVersion, scenario.installed);
|
|
712
|
+
assert.equal(result.report.versionState, scenario.name);
|
|
713
|
+
for (const key of ["manifest", "blockers", "warnings", "activeTransaction", "activeLock", "rollbackAvailable", "cleanupResidue"]) {
|
|
714
|
+
assert.ok(Object.hasOwn(result.report, key), `missing safe report key ${key}`);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
await t.test("invalid-version-state", async (child) => {
|
|
720
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
721
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
722
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
723
|
+
const result = await managerFixture(sourceRoot, { versionProvider: () => "v1.0.27" }).run("doctor", { targetRoot });
|
|
724
|
+
assert.equal(result.exitCode, 2);
|
|
725
|
+
assert.equal(result.report.sourceVersion, null);
|
|
726
|
+
assert.equal(result.report.installedVersion, "1.0.27");
|
|
727
|
+
assert.equal(result.report.versionState, "invalid-version-state");
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
test("[V022] doctor distinguishes absent from present invalid manifests", async (t) => {
|
|
732
|
+
await t.test("absent", async (child) => {
|
|
733
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
734
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
735
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
736
|
+
assert.equal(result.exitCode, 1);
|
|
737
|
+
assert.equal(result.report.manifest, "absent");
|
|
738
|
+
assert.equal(result.report.sourceVersion, "1.0.27");
|
|
739
|
+
assert.equal(result.report.installedVersion, null);
|
|
740
|
+
assert.equal(result.report.versionState, "not-installed");
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
for (const [name, bytes] of [["malformed", "{bad\n"], ["invalid-version", `${JSON.stringify(validManifest({ kit_version: "v1.0.27" }))}\n`]]) {
|
|
744
|
+
await t.test(name, async (child) => {
|
|
745
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
746
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
747
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
748
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "manifest.json"), bytes);
|
|
749
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
750
|
+
assert.equal(result.exitCode, 2);
|
|
751
|
+
assert.equal(result.report.manifest, "invalid");
|
|
752
|
+
assert.equal(result.report.sourceVersion, "1.0.27");
|
|
753
|
+
assert.equal(result.report.installedVersion, null);
|
|
754
|
+
assert.equal(result.report.versionState, "invalid-version-state");
|
|
755
|
+
assert.notEqual(result.report.versionState, "not-installed");
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
test("[V020] acknowledgement cannot bypass a newer source transition", async (t) => {
|
|
761
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
762
|
+
const source = put(sourceRoot, "opencode.json", "source\n");
|
|
763
|
+
const target = put(targetRoot, "opencode.json", "user\n", 0o600);
|
|
764
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.26" }).run("install", { targetRoot });
|
|
765
|
+
const manifestPath = path.join(targetRoot, ".oak", "manifest.json");
|
|
766
|
+
const before = fs.readFileSync(manifestPath);
|
|
767
|
+
const output = capture();
|
|
768
|
+
|
|
769
|
+
const result = await managerFixture(sourceRoot, {
|
|
770
|
+
stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: output.stream,
|
|
771
|
+
}).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
772
|
+
|
|
773
|
+
assert.equal(result.exitCode, 1);
|
|
774
|
+
assert.equal(result.versionState, "upgrade-available");
|
|
775
|
+
assert.equal(output.read(), "");
|
|
776
|
+
assert.deepEqual(fs.readFileSync(manifestPath), before);
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
test("[V023] version upgrade snapshots record both identities", async (t) => {
|
|
780
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
781
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
782
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.26" }).run("install", { targetRoot });
|
|
783
|
+
const result = await managerFixture(sourceRoot).run("upgrade", { targetRoot });
|
|
784
|
+
const rollback = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json"), "utf8"));
|
|
785
|
+
|
|
786
|
+
assert.equal(result.transaction.previous_manifest.kit_version, "1.0.26");
|
|
787
|
+
assert.equal(result.transaction.next_manifest.kit_version, "1.0.27");
|
|
788
|
+
assert.equal(rollback.previous_manifest.kit_version, "1.0.26");
|
|
789
|
+
assert.equal(rollback.next_manifest.kit_version, "1.0.27");
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
test("[V024] rollback restores the previous kit version", async (t) => {
|
|
793
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
794
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
795
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.26" }).run("install", { targetRoot });
|
|
796
|
+
await managerFixture(sourceRoot).run("upgrade", { targetRoot });
|
|
797
|
+
|
|
798
|
+
const result = await managerFixture(sourceRoot).run("rollback", { targetRoot });
|
|
799
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
800
|
+
|
|
801
|
+
assert.equal(result.exitCode, 0);
|
|
802
|
+
assert.equal(manifest.kit_version, "1.0.26");
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
test("[V025] rollback of the initial versioned install restores manifest absence", async (t) => {
|
|
806
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
807
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
808
|
+
const manager = managerFixture(sourceRoot);
|
|
809
|
+
await manager.run("install", { targetRoot });
|
|
810
|
+
|
|
811
|
+
assert.equal((await manager.run("rollback", { targetRoot })).exitCode, 0);
|
|
812
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "manifest.json")), false);
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
test("[V026] interrupted recovery uses journal versions when the provider changes", async (t) => {
|
|
816
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
817
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
818
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.26" }).run("install", { targetRoot });
|
|
819
|
+
const interrupted = await managerFixture(sourceRoot, {
|
|
820
|
+
failpoint(name) { if (name === "after-journal-create") throw new Error("crash"); },
|
|
821
|
+
}).run("upgrade", { targetRoot });
|
|
822
|
+
assert.equal(interrupted.exitCode, 2);
|
|
823
|
+
|
|
824
|
+
const recovered = await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("rollback", { targetRoot });
|
|
825
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
826
|
+
assert.equal(recovered.exitCode, 0);
|
|
827
|
+
assert.equal(manifest.kit_version, "1.0.26");
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
test("[V027] corrupt version state remains fail-closed across diagnostics and recovery", async (t) => {
|
|
831
|
+
await t.test("doctor retains lock evidence", async (child) => {
|
|
832
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
833
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
834
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
835
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "manifest.json"), `${JSON.stringify(validManifest({ kit_version: "v1.0.27" }))}\n`);
|
|
836
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "lock.json"), `${JSON.stringify({
|
|
837
|
+
transaction_id: "tx-live", pid: process.pid, command: "upgrade", created_at: "2026-07-20T00:00:00.000Z",
|
|
838
|
+
})}\n`);
|
|
839
|
+
const result = await managerFixture(sourceRoot, { pidProbe: () => ({ alive: true }) }).run("doctor", { targetRoot });
|
|
840
|
+
assert.equal(result.exitCode, 2);
|
|
841
|
+
assert.equal(result.report.versionState, "invalid-version-state");
|
|
842
|
+
assert.ok(result.report.activeLock);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
await t.test("rollback rejects a version-corrupted journal digest", async (child) => {
|
|
846
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
847
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
848
|
+
const manager = managerFixture(sourceRoot);
|
|
849
|
+
await manager.run("install", { targetRoot });
|
|
850
|
+
const transactionPath = path.join(targetRoot, ".oak", "rollback", "transaction.json");
|
|
851
|
+
const transaction = JSON.parse(fs.readFileSync(transactionPath, "utf8"));
|
|
852
|
+
transaction.next_manifest.kit_version = "1.0.26";
|
|
853
|
+
fs.writeFileSync(transactionPath, `${JSON.stringify(transaction)}\n`);
|
|
854
|
+
const before = fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
855
|
+
const result = await manager.run("rollback", { targetRoot });
|
|
856
|
+
assert.equal(result.exitCode, 2);
|
|
857
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json")), before);
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
await t.test("unsafe target state is not mislabeled as a version error", async (child) => {
|
|
861
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
862
|
+
const owned = put(sourceRoot, "agents/lead.md", "lead\n");
|
|
863
|
+
persistManifest(targetRoot, validManifest({
|
|
864
|
+
payload_sha256: inventorySource(sourceRoot).payloadSha256,
|
|
865
|
+
owned_files: [owned],
|
|
866
|
+
preserved_files: [],
|
|
867
|
+
}));
|
|
868
|
+
fs.mkdirSync(path.join(targetRoot, "agents"), { recursive: true });
|
|
869
|
+
fs.symlinkSync(path.join(sourceRoot, "agents", "lead.md"), path.join(targetRoot, "agents", "lead.md"));
|
|
870
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
871
|
+
assert.equal(result.exitCode, 2);
|
|
872
|
+
assert.match(result.error.message, /symlink/i);
|
|
873
|
+
assert.equal(result.report, undefined);
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
await t.test("source provider I/O failure remains a generic error", async (child) => {
|
|
877
|
+
const { sourceRoot, targetRoot } = makeFixture(child);
|
|
878
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
879
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
880
|
+
const ioError = Object.assign(new Error("source read failed"), { code: "EACCES" });
|
|
881
|
+
const result = await managerFixture(sourceRoot, { versionProvider() { throw ioError; } }).run("doctor", { targetRoot });
|
|
882
|
+
assert.equal(result.exitCode, 2);
|
|
883
|
+
assert.equal(result.error, ioError);
|
|
884
|
+
assert.equal(result.report, undefined);
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
test("[S002] clean install writes owned files and a valid sorted manifest", async (t) => {
|
|
889
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
890
|
+
const lead = put(sourceRoot, "agents/lead.md", "lead\n", 0o640);
|
|
891
|
+
put(sourceRoot, "commands/feature.md", "feature\n", 0o644);
|
|
892
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
893
|
+
assert.equal(result.exitCode, 0);
|
|
894
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "lead\n");
|
|
895
|
+
assert.equal(fs.statSync(path.join(targetRoot, "agents/lead.md")).mode & 0o777, 0o640);
|
|
896
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
897
|
+
validateManifest(manifest);
|
|
898
|
+
assert.deepEqual(manifest.owned_files.map((entry) => entry.path), ["agents/lead.md", "commands/feature.md"]);
|
|
899
|
+
assert.equal(manifest.owned_files[0].sha256, lead.sha256);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
test("[S006] initial force captures rollback bytes before replacement", async (t) => {
|
|
903
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
904
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
905
|
+
put(targetRoot, "agents/lead.md", "old-secret\n", 0o600);
|
|
906
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot, force: true });
|
|
907
|
+
assert.equal(result.exitCode, 0);
|
|
908
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "new\n");
|
|
909
|
+
const journal = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json"), "utf8"));
|
|
910
|
+
assert.equal(journal.operations[0].kind, "update");
|
|
911
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, ".oak", "rollback", journal.operations[0].backup_path), "utf8"), "old-secret\n");
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
test("[S011] uninstall removes unchanged owned files and preserves later user edits", async (t) => {
|
|
915
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
916
|
+
put(sourceRoot, "agents/keep.md", "original\n");
|
|
917
|
+
put(sourceRoot, "agents/remove.md", "remove\n");
|
|
918
|
+
const manager = managerFixture(sourceRoot);
|
|
919
|
+
assert.equal((await manager.run("install", { targetRoot })).exitCode, 0);
|
|
920
|
+
fs.writeFileSync(path.join(targetRoot, "agents/keep.md"), "user edit\n");
|
|
921
|
+
assert.equal((await manager.run("uninstall", { targetRoot, yes: true })).exitCode, 0);
|
|
922
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/keep.md"), "utf8"), "user edit\n");
|
|
923
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/remove.md")), false);
|
|
924
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "manifest.json")), false);
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
test("[S012] one committed rollback reverses install, upgrade, and uninstall", async (t) => {
|
|
928
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
929
|
+
put(sourceRoot, "agents/lead.md", "v1\n");
|
|
930
|
+
const manager = managerFixture(sourceRoot);
|
|
931
|
+
await manager.run("install", { targetRoot });
|
|
932
|
+
assert.equal((await manager.run("rollback", { targetRoot })).exitCode, 0);
|
|
933
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), false);
|
|
934
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "manifest.json")), false);
|
|
935
|
+
|
|
936
|
+
await manager.run("install", { targetRoot });
|
|
937
|
+
fs.writeFileSync(path.join(sourceRoot, "agents/lead.md"), "v2\n");
|
|
938
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("upgrade", { targetRoot });
|
|
939
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "v2\n");
|
|
940
|
+
await manager.run("rollback", { targetRoot });
|
|
941
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "v1\n");
|
|
942
|
+
|
|
943
|
+
await manager.run("uninstall", { targetRoot, yes: true });
|
|
944
|
+
await manager.run("rollback", { targetRoot });
|
|
945
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "v1\n");
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
test("[S015] simulated interruption leaves a valid recoverable journal", async (t) => {
|
|
949
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
950
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
951
|
+
const manager = managerFixture(sourceRoot, {
|
|
952
|
+
failpoint(name) { if (name === "after-journal-create") throw new Error("simulated crash"); },
|
|
953
|
+
});
|
|
954
|
+
const result = await manager.run("install", { targetRoot });
|
|
955
|
+
assert.equal(result.exitCode, 2);
|
|
956
|
+
const journal = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "transaction.json"), "utf8"));
|
|
957
|
+
validateTransaction(journal);
|
|
958
|
+
assert.equal(journal.status, "planned");
|
|
959
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "lock.json")), true);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
test("[S016] rollback recovers an interrupted forward operation to exact pre-state", async (t) => {
|
|
963
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
964
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
965
|
+
await managerFixture(sourceRoot, {
|
|
966
|
+
failpoint(name) { if (name === "after-journal-create") throw new Error("simulated crash"); },
|
|
967
|
+
}).run("install", { targetRoot });
|
|
968
|
+
|
|
969
|
+
const result = await managerFixture(sourceRoot).run("rollback", { targetRoot });
|
|
970
|
+
assert.equal(result.exitCode, 0);
|
|
971
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), false);
|
|
972
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "transaction.json")), false);
|
|
973
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "lock.json")), false);
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
function preservedFixture(t) {
|
|
977
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
978
|
+
const source = put(sourceRoot, "opencode.json", "source-v1\n", 0o644);
|
|
979
|
+
const target = put(targetRoot, "opencode.json", "user-v1\n", 0o600);
|
|
980
|
+
const manifest = validManifest({
|
|
981
|
+
payload_sha256: inventorySource(sourceRoot).payloadSha256,
|
|
982
|
+
owned_files: [],
|
|
983
|
+
preserved_files: [{
|
|
984
|
+
path: "opencode.json",
|
|
985
|
+
observed_sha256: target.sha256,
|
|
986
|
+
observed_mode: target.mode,
|
|
987
|
+
source_sha256: source.sha256,
|
|
988
|
+
source_mode: source.mode,
|
|
989
|
+
reason: "preexisting-user-file",
|
|
990
|
+
merge_acknowledgement: null,
|
|
991
|
+
}],
|
|
992
|
+
});
|
|
993
|
+
persistManifest(targetRoot, manifest);
|
|
994
|
+
return { sourceRoot, targetRoot, source, target, manifest };
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function ackLine(source, target, relative = "opencode.json") {
|
|
998
|
+
return `ACK-PRESERVED ${relative} ${target.sha256} ${target.mode.toString(8).padStart(4, "0")} ${source.sha256} ${source.mode.toString(8).padStart(4, "0")}`;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
test("[S021] stable preserved configuration is doctor-healthy", async (t) => {
|
|
1002
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1003
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1004
|
+
assert.equal(result.exitCode, 0);
|
|
1005
|
+
assert.deepEqual(result.report.warnings.map((warning) => warning.classification), ["preserved-stable"]);
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
test("[S022] source-only protected change creates a manual-merge warning", async (t) => {
|
|
1009
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1010
|
+
fs.writeFileSync(path.join(sourceRoot, "opencode.json"), "source-v2\n");
|
|
1011
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1012
|
+
assert.equal(result.exitCode, 1);
|
|
1013
|
+
assert.deepEqual(result.report.warnings.map((warning) => warning.classification), ["preserved-source-changed"]);
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
test("[S023] user and source changes remain merge-pending on both sides", async (t) => {
|
|
1017
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1018
|
+
fs.writeFileSync(path.join(sourceRoot, "opencode.json"), "source-v2\n");
|
|
1019
|
+
fs.writeFileSync(path.join(targetRoot, "opencode.json"), "user-v2\n");
|
|
1020
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1021
|
+
assert.equal(result.exitCode, 1);
|
|
1022
|
+
assert.deepEqual(result.report.warnings.map((warning) => warning.classification), ["preserved-both-changed"]);
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
test("[S080] doctor reports user-only evolution without refreshing baselines", async (t) => {
|
|
1026
|
+
const { sourceRoot, targetRoot, manifest } = preservedFixture(t);
|
|
1027
|
+
fs.writeFileSync(path.join(targetRoot, "opencode.json"), "user-v2\n");
|
|
1028
|
+
const before = fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
1029
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1030
|
+
assert.equal(result.exitCode, 0);
|
|
1031
|
+
assert.deepEqual(result.report.warnings.map((warning) => warning.classification), ["preserved-user-changed"]);
|
|
1032
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json")), before);
|
|
1033
|
+
assert.equal(JSON.parse(before).preserved_files[0].observed_sha256, manifest.preserved_files[0].observed_sha256);
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
test("[S111] generic yes is not preserved-merge authorization", async (t) => {
|
|
1037
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1038
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from(["yes\n"]), stdout: capture().stream }).run("doctor", {
|
|
1039
|
+
targetRoot,
|
|
1040
|
+
acceptPreserved: "opencode.json",
|
|
1041
|
+
});
|
|
1042
|
+
assert.equal(result.exitCode, 1);
|
|
1043
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8")).preserved_files[0].merge_acknowledgement, null);
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
test("[S115] exact ACK through non-interactive stdin commits acknowledgement", async (t) => {
|
|
1047
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1048
|
+
const line = `ACK-PRESERVED opencode.json ${target.sha256} 0600 ${source.sha256} 0644`;
|
|
1049
|
+
const stdout = capture();
|
|
1050
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${line}\n`]), stdout: stdout.stream });
|
|
1051
|
+
const result = await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1052
|
+
assert.equal(result.exitCode, 0);
|
|
1053
|
+
assert.match(stdout.read(), new RegExp(`${line.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\n`));
|
|
1054
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1055
|
+
assert.equal(manifest.preserved_files[0].reason, "preexisting-user-file");
|
|
1056
|
+
assert.deepEqual(manifest.preserved_files[0].merge_acknowledgement, {
|
|
1057
|
+
target_sha256: target.sha256,
|
|
1058
|
+
target_mode: 0o600,
|
|
1059
|
+
source_sha256: source.sha256,
|
|
1060
|
+
source_mode: 0o644,
|
|
1061
|
+
acknowledged_at: "2026-07-20T00:00:00.000Z",
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
test("[S017] apparently live lock rejects a second mutation", async (t) => {
|
|
1066
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1067
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1068
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1069
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "lock.json"), JSON.stringify({
|
|
1070
|
+
transaction_id: "other",
|
|
1071
|
+
pid: 4321,
|
|
1072
|
+
command: "install",
|
|
1073
|
+
created_at: "2026-07-20T00:00:00.000Z",
|
|
1074
|
+
}));
|
|
1075
|
+
const result = await managerFixture(sourceRoot, { pidProbe: () => ({ alive: true }) }).run("install", { targetRoot });
|
|
1076
|
+
assert.equal(result.exitCode, 1);
|
|
1077
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), false);
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
test("[S018] stale lock plus corrupt transaction is reported without mutation", async (t) => {
|
|
1081
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1082
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1083
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1084
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "lock.json"), JSON.stringify({
|
|
1085
|
+
transaction_id: "other", pid: 4321, command: "install", created_at: "2026-07-20T00:00:00.000Z",
|
|
1086
|
+
}));
|
|
1087
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "transaction.json"), "{not-json");
|
|
1088
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1089
|
+
assert.equal(result.exitCode, 2);
|
|
1090
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), false);
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
test("[S079] EPERM from PID probe blocks conservatively", async (t) => {
|
|
1094
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1095
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1096
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1097
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "lock.json"), JSON.stringify({
|
|
1098
|
+
transaction_id: "other", pid: 4321, command: "install", created_at: "2026-07-20T00:00:00.000Z",
|
|
1099
|
+
}));
|
|
1100
|
+
const result = await managerFixture(sourceRoot, { pidProbe() { const error = new Error("denied"); error.code = "EPERM"; throw error; } }).run("install", { targetRoot });
|
|
1101
|
+
assert.equal(result.exitCode, 1);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
test("[S094] ambiguous PID-probe errors fail closed", async (t) => {
|
|
1105
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1106
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1107
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1108
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "lock.json"), JSON.stringify({
|
|
1109
|
+
transaction_id: "other", pid: 4321, command: "install", created_at: "2026-07-20T00:00:00.000Z",
|
|
1110
|
+
}));
|
|
1111
|
+
const result = await managerFixture(sourceRoot, { pidProbe() { const error = new Error("ambiguous"); error.code = "EIO"; throw error; } }).run("install", { targetRoot });
|
|
1112
|
+
assert.equal(result.exitCode, 2);
|
|
1113
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "lock.json")), true);
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
test("[S043] failure before journal creation leaves zero persistent state", async (t) => {
|
|
1117
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1118
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1119
|
+
const result = await managerFixture(sourceRoot, {
|
|
1120
|
+
failpoint(name) { if (name === "before-journal-create") throw new Error("stop"); },
|
|
1121
|
+
}).run("install", { targetRoot });
|
|
1122
|
+
assert.equal(result.exitCode, 2);
|
|
1123
|
+
assert.equal(fs.existsSync(targetRoot), false);
|
|
1124
|
+
|
|
1125
|
+
const second = makeFixture(t);
|
|
1126
|
+
put(second.sourceRoot, "agents/lead.md", "new\n");
|
|
1127
|
+
put(second.targetRoot, "agents/lead.md", "old-secret\n");
|
|
1128
|
+
const failingFs = new Proxy(fs, {
|
|
1129
|
+
get(target, property) {
|
|
1130
|
+
if (property === "renameSync") {
|
|
1131
|
+
return (from, to) => {
|
|
1132
|
+
if (to === path.join(second.targetRoot, ".oak", "transaction.json")) throw Object.assign(new Error("journal rename failed"), { code: "EIO" });
|
|
1133
|
+
return target.renameSync(from, to);
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
const value = Reflect.get(target, property);
|
|
1137
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
1138
|
+
},
|
|
1139
|
+
});
|
|
1140
|
+
const failedPublication = await managerFixture(second.sourceRoot, { fsOps: failingFs }).run("install", {
|
|
1141
|
+
targetRoot: second.targetRoot,
|
|
1142
|
+
force: true,
|
|
1143
|
+
});
|
|
1144
|
+
assert.equal(failedPublication.exitCode, 2);
|
|
1145
|
+
assert.equal(fs.readFileSync(path.join(second.targetRoot, "agents/lead.md"), "utf8"), "old-secret\n");
|
|
1146
|
+
assert.equal(fs.existsSync(path.join(second.targetRoot, ".oak")), false);
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
test("[S092] no-op upgrade leaves manifest and preserved baselines byte-for-byte unchanged", async (t) => {
|
|
1150
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1151
|
+
put(sourceRoot, "agents/lead.md", "same\n");
|
|
1152
|
+
const manager = managerFixture(sourceRoot);
|
|
1153
|
+
await manager.run("install", { targetRoot });
|
|
1154
|
+
const before = fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
1155
|
+
const result = await manager.run("upgrade", { targetRoot });
|
|
1156
|
+
assert.equal(result.exitCode, 0);
|
|
1157
|
+
assert.equal(result.plan.hasWork, false);
|
|
1158
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json")), before);
|
|
1159
|
+
});
|
|
1160
|
+
|
|
1161
|
+
test("[S103] obsolete preserved present is classified without becoming owned", (t) => {
|
|
1162
|
+
const { sourceRoot, targetRoot, manifest } = preservedFixture(t);
|
|
1163
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1164
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
1165
|
+
assert.equal(plan.warnings[0].classification, "obsolete-preserved-present");
|
|
1166
|
+
assert.equal(plan.nextManifest.owned_files.some((entry) => entry.path === "opencode.json"), false);
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
test("[S104] obsolete preserved missing is classified distinctly", (t) => {
|
|
1170
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1171
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1172
|
+
fs.unlinkSync(path.join(targetRoot, "opencode.json"));
|
|
1173
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
1174
|
+
assert.equal(plan.warnings[0].classification, "obsolete-preserved-missing");
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
test("[S105] upgrade cleans obsolete-preserved metadata without touching present user bytes", async (t) => {
|
|
1178
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1179
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1180
|
+
const before = fs.readFileSync(path.join(targetRoot, "opencode.json"));
|
|
1181
|
+
const result = await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("upgrade", { targetRoot });
|
|
1182
|
+
assert.equal(result.exitCode, 0);
|
|
1183
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, "opencode.json")), before);
|
|
1184
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1185
|
+
assert.deepEqual(manifest.preserved_files, []);
|
|
1186
|
+
});
|
|
1187
|
+
|
|
1188
|
+
test("[S106] upgrade cleans obsolete-preserved metadata without recreating a missing file", async (t) => {
|
|
1189
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1190
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1191
|
+
fs.unlinkSync(path.join(targetRoot, "opencode.json"));
|
|
1192
|
+
const result = await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("upgrade", { targetRoot });
|
|
1193
|
+
assert.equal(result.exitCode, 0);
|
|
1194
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "opencode.json")), false);
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
test("[S107] rollback of obsolete cleanup restores metadata only", async (t) => {
|
|
1198
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1199
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1200
|
+
const before = fs.readFileSync(path.join(targetRoot, "opencode.json"));
|
|
1201
|
+
const manager = managerFixture(sourceRoot, { versionProvider: () => "1.0.28" });
|
|
1202
|
+
await manager.run("upgrade", { targetRoot });
|
|
1203
|
+
await manager.run("rollback", { targetRoot });
|
|
1204
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, "opencode.json")), before);
|
|
1205
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1206
|
+
assert.equal(manifest.preserved_files[0].path, "opencode.json");
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1209
|
+
test("[S108] doctor reports obsolete preservation as actionable and offers no ACK", async (t) => {
|
|
1210
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1211
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1212
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1213
|
+
assert.equal(result.exitCode, 1);
|
|
1214
|
+
assert.equal(result.report.warnings[0].classification, "obsolete-preserved-present");
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1217
|
+
test("[S109] obsolete cleanup commits as a manifest-only upgrade", async (t) => {
|
|
1218
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1219
|
+
fs.unlinkSync(path.join(sourceRoot, "opencode.json"));
|
|
1220
|
+
const result = await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("upgrade", { targetRoot });
|
|
1221
|
+
assert.equal(result.exitCode, 0);
|
|
1222
|
+
assert.deepEqual(result.transaction.operations, []);
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
test("[S110] accept-preserved requires and displays the complete canonical ACK line", async (t) => {
|
|
1226
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1227
|
+
const stdout = capture();
|
|
1228
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([]), stdout: stdout.stream }).run("doctor", {
|
|
1229
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1230
|
+
});
|
|
1231
|
+
assert.equal(result.exitCode, 1);
|
|
1232
|
+
assert.equal(stdout.read(), `${ackLine(source, target)}\n`);
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
test("[S112] path-only preserved confirmation is rejected", async (t) => {
|
|
1236
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1237
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from(["opencode.json\n"]), stdout: capture().stream }).run("doctor", {
|
|
1238
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1239
|
+
});
|
|
1240
|
+
assert.equal(result.exitCode, 1);
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
test("[S113] truncated hashes in preserved confirmation are rejected", async (t) => {
|
|
1244
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1245
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target).slice(0, -8)}\n`]), stdout: capture().stream }).run("doctor", {
|
|
1246
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1247
|
+
});
|
|
1248
|
+
assert.equal(result.exitCode, 1);
|
|
1249
|
+
});
|
|
1250
|
+
|
|
1251
|
+
test("[S114] EOF cancels acknowledgement with zero persistent mutation", async (t) => {
|
|
1252
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1253
|
+
const before = fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
1254
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([]), stdout: capture().stream }).run("doctor", {
|
|
1255
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1256
|
+
});
|
|
1257
|
+
assert.equal(result.exitCode, 1);
|
|
1258
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json")), before);
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
test("[S116] tuple change after confirmation aborts before transaction state", async (t) => {
|
|
1262
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1263
|
+
const result = await managerFixture(sourceRoot, {
|
|
1264
|
+
stdin: Readable.from([`${ackLine(source, target)}\n`]),
|
|
1265
|
+
stdout: capture().stream,
|
|
1266
|
+
failpoint(name) {
|
|
1267
|
+
if (name === "after-ack-confirmation") fs.writeFileSync(path.join(targetRoot, "opencode.json"), "raced\n");
|
|
1268
|
+
},
|
|
1269
|
+
}).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1270
|
+
assert.equal(result.exitCode, 1);
|
|
1271
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "transaction.json")), false);
|
|
1272
|
+
});
|
|
1273
|
+
|
|
1274
|
+
test("[S117] acknowledgement path absent from preserved_files is invalid invocation", async (t) => {
|
|
1275
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1276
|
+
const source = put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1277
|
+
put(targetRoot, "agents/lead.md", "lead\n");
|
|
1278
|
+
persistManifest(targetRoot, validManifest({
|
|
1279
|
+
payload_sha256: inventorySource(sourceRoot).payloadSha256,
|
|
1280
|
+
owned_files: [source],
|
|
1281
|
+
preserved_files: [],
|
|
1282
|
+
}));
|
|
1283
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([]), stdout: capture().stream }).run("doctor", {
|
|
1284
|
+
targetRoot, acceptPreserved: "agents/lead.md",
|
|
1285
|
+
});
|
|
1286
|
+
assert.equal(result.exitCode, 2);
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
test("[S118] unrelated owned drift blocks acknowledgement", async (t) => {
|
|
1290
|
+
const { sourceRoot, targetRoot, source, target, manifest } = preservedFixture(t);
|
|
1291
|
+
const owned = put(sourceRoot, "agents/lead.md", "owned\n");
|
|
1292
|
+
put(targetRoot, "agents/lead.md", "modified\n");
|
|
1293
|
+
manifest.owned_files = [owned];
|
|
1294
|
+
persistManifest(targetRoot, manifest);
|
|
1295
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream }).run("doctor", {
|
|
1296
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1297
|
+
});
|
|
1298
|
+
assert.equal(result.exitCode, 1);
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
test("[S119] warning on another preserved file does not block acknowledgement", async (t) => {
|
|
1302
|
+
const { sourceRoot, targetRoot, source, target, manifest } = preservedFixture(t);
|
|
1303
|
+
const otherSource = put(sourceRoot, "tui.json", "source\n");
|
|
1304
|
+
manifest.preserved_files.push({
|
|
1305
|
+
path: "tui.json", observed_sha256: HASH_A, observed_mode: 0o600,
|
|
1306
|
+
source_sha256: otherSource.sha256, source_mode: otherSource.mode,
|
|
1307
|
+
reason: "preexisting-user-file", merge_acknowledgement: null,
|
|
1308
|
+
});
|
|
1309
|
+
manifest.payload_sha256 = inventorySource(sourceRoot).payloadSha256;
|
|
1310
|
+
persistManifest(targetRoot, manifest);
|
|
1311
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream }).run("doctor", {
|
|
1312
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1313
|
+
});
|
|
1314
|
+
assert.equal(result.exitCode, 0);
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1317
|
+
test("[S120] acknowledgement preserves original provenance reason", async (t) => {
|
|
1318
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1319
|
+
await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream }).run("doctor", {
|
|
1320
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1321
|
+
});
|
|
1322
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1323
|
+
assert.equal(manifest.preserved_files[0].reason, "preexisting-user-file");
|
|
1324
|
+
});
|
|
1325
|
+
|
|
1326
|
+
test("[S121] acknowledgement matches committed baselines", async (t) => {
|
|
1327
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1328
|
+
await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream }).run("doctor", {
|
|
1329
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1330
|
+
});
|
|
1331
|
+
const entry = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8")).preserved_files[0];
|
|
1332
|
+
assert.equal(entry.merge_acknowledgement.target_sha256, entry.observed_sha256);
|
|
1333
|
+
assert.equal(entry.merge_acknowledgement.source_sha256, entry.source_sha256);
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
test("[S122] acknowledgement timestamp uses injectable clock", async (t) => {
|
|
1337
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1338
|
+
await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream }).run("doctor", {
|
|
1339
|
+
targetRoot, acceptPreserved: "opencode.json",
|
|
1340
|
+
});
|
|
1341
|
+
const entry = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8")).preserved_files[0];
|
|
1342
|
+
assert.equal(entry.merge_acknowledgement.acknowledged_at, "2026-07-20T00:00:00.000Z");
|
|
1343
|
+
});
|
|
1344
|
+
|
|
1345
|
+
test("[S123] rollback restores prior acknowledgement object", async (t) => {
|
|
1346
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1347
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream });
|
|
1348
|
+
await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1349
|
+
await manager.run("rollback", { targetRoot });
|
|
1350
|
+
const entry = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8")).preserved_files[0];
|
|
1351
|
+
assert.equal(entry.merge_acknowledgement, null);
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
test("[S126] source change leaves acknowledgement historical and merge-pending", async (t) => {
|
|
1355
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1356
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream });
|
|
1357
|
+
await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1358
|
+
fs.writeFileSync(path.join(sourceRoot, "opencode.json"), "source-v2\n");
|
|
1359
|
+
const result = await manager.run("doctor", { targetRoot });
|
|
1360
|
+
assert.equal(result.report.warnings[0].classification, "preserved-source-changed");
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
test("[S127] target change leaves acknowledgement historical and user-only", async (t) => {
|
|
1364
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1365
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream });
|
|
1366
|
+
await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1367
|
+
fs.writeFileSync(path.join(targetRoot, "opencode.json"), "user-v2\n");
|
|
1368
|
+
const result = await manager.run("doctor", { targetRoot });
|
|
1369
|
+
assert.equal(result.report.warnings[0].classification, "preserved-user-changed");
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1372
|
+
test("[S025] source-file target-directory collision fails without mutation", async (t) => {
|
|
1373
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1374
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1375
|
+
fs.mkdirSync(path.join(targetRoot, "agents", "lead.md"), { recursive: true });
|
|
1376
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1377
|
+
assert.equal(result.exitCode, 1);
|
|
1378
|
+
assert.equal(fs.statSync(path.join(targetRoot, "agents", "lead.md")).isDirectory(), true);
|
|
1379
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak")), false);
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
test("[S026] source-directory target-file collision fails closed", async (t) => {
|
|
1383
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1384
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1385
|
+
put(targetRoot, "agents", "user-file\n");
|
|
1386
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1387
|
+
assert.equal(result.exitCode, 2);
|
|
1388
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents"), "utf8"), "user-file\n");
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
test("[S027] .oak as regular file fails closed", async (t) => {
|
|
1392
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1393
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1394
|
+
put(targetRoot, ".oak", "user\n");
|
|
1395
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1396
|
+
assert.equal(result.exitCode, 2);
|
|
1397
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, ".oak"), "utf8"), "user\n");
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
test("[S028] .oak as symlink fails closed", async (t) => {
|
|
1401
|
+
const { root, sourceRoot, targetRoot } = makeFixture(t);
|
|
1402
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1403
|
+
fs.mkdirSync(targetRoot, { recursive: true });
|
|
1404
|
+
fs.mkdirSync(path.join(root, "outside"));
|
|
1405
|
+
fs.symlinkSync(path.join(root, "outside"), path.join(targetRoot, ".oak"));
|
|
1406
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1407
|
+
assert.equal(result.exitCode, 2);
|
|
1408
|
+
assert.deepEqual(fs.readdirSync(path.join(root, "outside")), []);
|
|
1409
|
+
});
|
|
1410
|
+
|
|
1411
|
+
test("[S036] force cannot replace a directory", async (t) => {
|
|
1412
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1413
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1414
|
+
fs.mkdirSync(path.join(targetRoot, "agents", "lead.md"), { recursive: true });
|
|
1415
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot, force: true });
|
|
1416
|
+
assert.equal(result.exitCode, 1);
|
|
1417
|
+
assert.equal(fs.statSync(path.join(targetRoot, "agents", "lead.md")).isDirectory(), true);
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
test("[S037] force cannot traverse or replace a symlink", async (t) => {
|
|
1421
|
+
const { root, sourceRoot, targetRoot } = makeFixture(t);
|
|
1422
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1423
|
+
fs.mkdirSync(path.join(targetRoot, "agents"), { recursive: true });
|
|
1424
|
+
put(root, "outside.md", "outside\n");
|
|
1425
|
+
fs.symlinkSync(path.join(root, "outside.md"), path.join(targetRoot, "agents", "lead.md"));
|
|
1426
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot, force: true });
|
|
1427
|
+
assert.equal(result.exitCode, 2);
|
|
1428
|
+
assert.equal(fs.readFileSync(path.join(root, "outside.md"), "utf8"), "outside\n");
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
test("[S038] state, backups, and temporaries use restrictive permissions", async (t) => {
|
|
1432
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1433
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
1434
|
+
put(targetRoot, "agents/lead.md", "old\n");
|
|
1435
|
+
await managerFixture(sourceRoot).run("install", { targetRoot, force: true });
|
|
1436
|
+
const mode = (relative) => fs.statSync(path.join(targetRoot, relative)).mode & 0o777;
|
|
1437
|
+
assert.equal(mode(".oak"), 0o700);
|
|
1438
|
+
assert.equal(mode(".oak/manifest.json"), 0o600);
|
|
1439
|
+
assert.equal(mode(".oak/rollback"), 0o700);
|
|
1440
|
+
assert.equal(mode(".oak/rollback/transaction.json"), 0o600);
|
|
1441
|
+
assert.equal(mode(".oak/rollback/files/000000"), 0o600);
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
test("[S081] nested .oak source payload path is rejected", (t) => {
|
|
1445
|
+
const { sourceRoot } = makeFixture(t);
|
|
1446
|
+
fs.mkdirSync(path.join(sourceRoot, ".oak"));
|
|
1447
|
+
fs.writeFileSync(path.join(sourceRoot, ".oak", "manifest.json"), "{}");
|
|
1448
|
+
assert.throws(() => inventorySource(sourceRoot), /reserved.*\.oak/i);
|
|
1449
|
+
});
|
|
1450
|
+
|
|
1451
|
+
test("[S082] target relationship hidden through an ancestor symlink is rejected", async (t) => {
|
|
1452
|
+
const { root, sourceRoot } = makeFixture(t);
|
|
1453
|
+
const link = path.join(root, "link");
|
|
1454
|
+
fs.symlinkSync(path.dirname(sourceRoot), link);
|
|
1455
|
+
const targetRoot = path.join(link, "opencode", "nested-target");
|
|
1456
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1457
|
+
assert.equal(result.exitCode, 2);
|
|
1458
|
+
assert.equal(fs.existsSync(path.join(sourceRoot, "nested-target")), false);
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1461
|
+
test("[S083] backup paths containing a reserved .oak component are rejected", () => {
|
|
1462
|
+
const transaction = validTransaction({ operation: {
|
|
1463
|
+
kind: "update", path: "agents/a.md", before_sha256: HASH_B, before_mode: 0o600,
|
|
1464
|
+
after_sha256: HASH_A, after_mode: 0o644, backup_path: "files/.oak/secret",
|
|
1465
|
+
} });
|
|
1466
|
+
assert.throws(() => validateTransaction(transaction), /reserved.*\.oak/i);
|
|
1467
|
+
});
|
|
1468
|
+
|
|
1469
|
+
test("[S013] user modification after commit blocks rollback", async (t) => {
|
|
1470
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1471
|
+
put(sourceRoot, "agents/lead.md", "installed\n");
|
|
1472
|
+
const manager = managerFixture(sourceRoot);
|
|
1473
|
+
await manager.run("install", { targetRoot });
|
|
1474
|
+
fs.writeFileSync(path.join(targetRoot, "agents/lead.md"), "user edit\n");
|
|
1475
|
+
const result = await manager.run("rollback", { targetRoot });
|
|
1476
|
+
assert.equal(result.exitCode, 1);
|
|
1477
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "user edit\n");
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1480
|
+
test("[S031] bootstrap cleanup never removes a pre-existing target", async (t) => {
|
|
1481
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1482
|
+
fs.mkdirSync(targetRoot);
|
|
1483
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1484
|
+
await managerFixture(sourceRoot, { failpoint(name) { if (name === "before-journal-create") throw new Error("stop"); } }).run("install", { targetRoot });
|
|
1485
|
+
assert.equal(fs.existsSync(targetRoot), true);
|
|
1486
|
+
assert.deepEqual(fs.readdirSync(targetRoot), []);
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
test("[S032] bootstrap cleanup removes an empty target created by the invocation", async (t) => {
|
|
1490
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1491
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1492
|
+
await managerFixture(sourceRoot, { failpoint(name) { if (name === "before-journal-create") throw new Error("stop"); } }).run("install", { targetRoot });
|
|
1493
|
+
assert.equal(fs.existsSync(targetRoot), false);
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
test("[S034] upgrade preserves changed executable modes", async (t) => {
|
|
1497
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1498
|
+
put(sourceRoot, "scripts/run.sh", "v1\n", 0o700);
|
|
1499
|
+
const manager = managerFixture(sourceRoot);
|
|
1500
|
+
await manager.run("install", { targetRoot });
|
|
1501
|
+
put(sourceRoot, "scripts/run.sh", "v2\n", 0o755);
|
|
1502
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("upgrade", { targetRoot });
|
|
1503
|
+
assert.equal(fs.statSync(path.join(targetRoot, "scripts/run.sh")).mode & 0o777, 0o755);
|
|
1504
|
+
});
|
|
1505
|
+
|
|
1506
|
+
test("[S035] rollback restores executable modes", async (t) => {
|
|
1507
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1508
|
+
put(sourceRoot, "scripts/run.sh", "v1\n", 0o700);
|
|
1509
|
+
const manager = managerFixture(sourceRoot);
|
|
1510
|
+
await manager.run("install", { targetRoot });
|
|
1511
|
+
put(sourceRoot, "scripts/run.sh", "v2\n", 0o755);
|
|
1512
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.28" }).run("upgrade", { targetRoot });
|
|
1513
|
+
await manager.run("rollback", { targetRoot });
|
|
1514
|
+
assert.equal(fs.statSync(path.join(targetRoot, "scripts/run.sh")).mode & 0o777, 0o700);
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
test("[S039] an apparently live PID blocks conservatively", async (t) => {
|
|
1518
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1519
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1520
|
+
fs.mkdirSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1521
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "lock.json"), JSON.stringify({ transaction_id: "live", pid: 9, command: "install", created_at: "2026-07-20T00:00:00.000Z" }));
|
|
1522
|
+
const result = await managerFixture(sourceRoot, { pidProbe: () => ({ alive: true }) }).run("install", { targetRoot });
|
|
1523
|
+
assert.equal(result.exitCode, 1);
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
test("[S040] journal completed indexes must refer to real operations", () => {
|
|
1527
|
+
const transaction = validTransaction();
|
|
1528
|
+
transaction.completed_operation_indexes = [0];
|
|
1529
|
+
assert.throws(() => validateTransaction(transaction), /completed indexes/i);
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
test("[S041] missing preserved source-overlapping file makes doctor actionable without recreation", async (t) => {
|
|
1533
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1534
|
+
fs.unlinkSync(path.join(targetRoot, "opencode.json"));
|
|
1535
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1536
|
+
assert.equal(result.exitCode, 1);
|
|
1537
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "opencode.json")), false);
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
test("[S042] stable preserved file is not an upgrade blocker", (t) => {
|
|
1541
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1542
|
+
const plan = planFixture("upgrade", sourceRoot, targetRoot);
|
|
1543
|
+
assert.equal(plan.canApply, true);
|
|
1544
|
+
assert.equal(plan.blockers.length, 0);
|
|
1545
|
+
});
|
|
1546
|
+
|
|
1547
|
+
test("[S044] post-journal interruption yields a deterministic doctor recovery report", async (t) => {
|
|
1548
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1549
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1550
|
+
await managerFixture(sourceRoot, { failpoint(name) { if (name === "after-journal-create") throw new Error("stop"); } }).run("install", { targetRoot });
|
|
1551
|
+
const result = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1552
|
+
assert.equal(result.exitCode, 1);
|
|
1553
|
+
assert.equal(result.report.activeTransaction, true);
|
|
1554
|
+
assert.equal(result.report.activeLock, "stale");
|
|
1555
|
+
});
|
|
1556
|
+
|
|
1557
|
+
test("[S045] interrupted-forward recovery retains the earlier committed rollback point", async (t) => {
|
|
1558
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1559
|
+
put(sourceRoot, "agents/lead.md", "v1\n");
|
|
1560
|
+
const manager = managerFixture(sourceRoot);
|
|
1561
|
+
await manager.run("install", { targetRoot });
|
|
1562
|
+
const prior = fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json"));
|
|
1563
|
+
put(sourceRoot, "agents/lead.md", "v2\n");
|
|
1564
|
+
await managerFixture(sourceRoot, {
|
|
1565
|
+
versionProvider: () => "1.0.28",
|
|
1566
|
+
transactionId: () => "tx-upgrade",
|
|
1567
|
+
failpoint(name) { if (name === "after-journal-create") throw new Error("stop"); },
|
|
1568
|
+
}).run("upgrade", { targetRoot });
|
|
1569
|
+
await manager.run("rollback", { targetRoot });
|
|
1570
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json")), prior);
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
test("[S047] errors never include sensitive rollback backup bytes", async (t) => {
|
|
1574
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1575
|
+
const sentinel = "SENSITIVE-BACKUP-SENTINEL";
|
|
1576
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
1577
|
+
put(targetRoot, "agents/lead.md", `${sentinel}\n`);
|
|
1578
|
+
const manager = managerFixture(sourceRoot);
|
|
1579
|
+
await manager.run("install", { targetRoot, force: true });
|
|
1580
|
+
fs.writeFileSync(path.join(targetRoot, "agents/lead.md"), "conflict\n");
|
|
1581
|
+
const result = await manager.run("rollback", { targetRoot });
|
|
1582
|
+
assert.equal(JSON.stringify(result).includes(sentinel), false);
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
test("[S049] invalid transaction status-origin combination fails closed", () => {
|
|
1586
|
+
const transaction = validTransaction();
|
|
1587
|
+
transaction.status = "mystery";
|
|
1588
|
+
assert.throws(() => validateTransaction(transaction), /status.*rollback_origin/i);
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
test("[S052] acknowledgement updates both baselines without changing ownership", async (t) => {
|
|
1592
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1593
|
+
await managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream }).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1594
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1595
|
+
assert.equal(manifest.owned_files.length, 0);
|
|
1596
|
+
assert.equal(manifest.preserved_files[0].observed_sha256, target.sha256);
|
|
1597
|
+
assert.equal(manifest.preserved_files[0].source_sha256, source.sha256);
|
|
1598
|
+
});
|
|
1599
|
+
|
|
1600
|
+
test("[S055] acknowledgement of a non-preserved path fails closed", async (t) => {
|
|
1601
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1602
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1603
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1604
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([]), stdout: capture().stream }).run("doctor", { targetRoot, acceptPreserved: "agents/lead.md" });
|
|
1605
|
+
assert.equal(result.exitCode, 2);
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
test("[S056] source change after acknowledgement is merge-pending again", async (t) => {
|
|
1609
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1610
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream });
|
|
1611
|
+
await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1612
|
+
fs.writeFileSync(path.join(sourceRoot, "opencode.json"), "new source\n");
|
|
1613
|
+
assert.equal((await manager.run("doctor", { targetRoot })).exitCode, 1);
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
test("[S057] user change after acknowledgement remains user-only evolution", async (t) => {
|
|
1617
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1618
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream });
|
|
1619
|
+
await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1620
|
+
fs.writeFileSync(path.join(targetRoot, "opencode.json"), "new user\n");
|
|
1621
|
+
assert.equal((await manager.run("doctor", { targetRoot })).exitCode, 0);
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1624
|
+
test("[S068] adoption changes ownership without rewriting the existing file", async (t) => {
|
|
1625
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1626
|
+
put(sourceRoot, "agents/lead.md", "same\n");
|
|
1627
|
+
put(targetRoot, "agents/lead.md", "same\n");
|
|
1628
|
+
const before = fs.statSync(path.join(targetRoot, "agents/lead.md")).mtimeMs;
|
|
1629
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1630
|
+
assert.equal(fs.statSync(path.join(targetRoot, "agents/lead.md")).mtimeMs, before);
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
test("[S069] rollback of adoption removes ownership without deleting the file", async (t) => {
|
|
1634
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1635
|
+
put(sourceRoot, "agents/lead.md", "same\n");
|
|
1636
|
+
put(targetRoot, "agents/lead.md", "same\n");
|
|
1637
|
+
const manager = managerFixture(sourceRoot);
|
|
1638
|
+
await manager.run("install", { targetRoot });
|
|
1639
|
+
await manager.run("rollback", { targetRoot });
|
|
1640
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "same\n");
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1643
|
+
test("[S070] preservation creates no filesystem operation or backup", async (t) => {
|
|
1644
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1645
|
+
fs.rmSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1646
|
+
const result = await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1647
|
+
assert.deepEqual(result.transaction.operations, []);
|
|
1648
|
+
assert.deepEqual(fs.readdirSync(path.join(targetRoot, ".oak", "rollback", "files")), []);
|
|
1649
|
+
});
|
|
1650
|
+
|
|
1651
|
+
test("[S071] rollback of preservation restores metadata without changing user bytes", async (t) => {
|
|
1652
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1653
|
+
fs.rmSync(path.join(targetRoot, ".oak"), { recursive: true });
|
|
1654
|
+
const before = fs.readFileSync(path.join(targetRoot, "opencode.json"));
|
|
1655
|
+
const manager = managerFixture(sourceRoot);
|
|
1656
|
+
await manager.run("install", { targetRoot });
|
|
1657
|
+
await manager.run("rollback", { targetRoot });
|
|
1658
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, "opencode.json")), before);
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
test("[S077] manifest-only adoption commits and rolls back with zero operations", async (t) => {
|
|
1662
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1663
|
+
put(sourceRoot, "agents/lead.md", "same\n");
|
|
1664
|
+
put(targetRoot, "agents/lead.md", "same\n");
|
|
1665
|
+
const manager = managerFixture(sourceRoot);
|
|
1666
|
+
const installed = await manager.run("install", { targetRoot });
|
|
1667
|
+
assert.deepEqual(installed.transaction.operations, []);
|
|
1668
|
+
assert.equal((await manager.run("rollback", { targetRoot })).exitCode, 0);
|
|
1669
|
+
});
|
|
1670
|
+
|
|
1671
|
+
test("[S078] acknowledgement is a rollbackable manifest-only transaction", async (t) => {
|
|
1672
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1673
|
+
const manager = managerFixture(sourceRoot, { stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream });
|
|
1674
|
+
const result = await manager.run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1675
|
+
assert.deepEqual(result.transaction.operations, []);
|
|
1676
|
+
assert.equal((await manager.run("rollback", { targetRoot })).exitCode, 0);
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1679
|
+
test("[S084] case-equivalent target relationships are rejected on case-insensitive filesystems", (t) => {
|
|
1680
|
+
const { sourceRoot } = makeFixture(t);
|
|
1681
|
+
const upper = sourceRoot.toUpperCase();
|
|
1682
|
+
if (upper === sourceRoot || !fs.existsSync(upper)) return t.skip("fixture filesystem is case-sensitive");
|
|
1683
|
+
assert.throws(() => assertSafeTarget({ targetRoot: upper, repositoryRoot: path.dirname(sourceRoot), sourceRoot }), /source payload/i);
|
|
1684
|
+
});
|
|
1685
|
+
|
|
1686
|
+
test("[S090] path-only authorization cannot acknowledge preserved state", async (t) => {
|
|
1687
|
+
const { sourceRoot, targetRoot } = preservedFixture(t);
|
|
1688
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from(["opencode.json\n"]), stdout: capture().stream }).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1689
|
+
assert.equal(result.exitCode, 1);
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
test("[S091] any mismatched ACK tuple field is rejected", async (t) => {
|
|
1693
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1694
|
+
const bad = ackLine(source, target).replace(" 0600 ", " 0644 ");
|
|
1695
|
+
const result = await managerFixture(sourceRoot, { stdin: Readable.from([`${bad}\n`]), stdout: capture().stream }).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1696
|
+
assert.equal(result.exitCode, 1);
|
|
1697
|
+
});
|
|
1698
|
+
|
|
1699
|
+
test("[S099] rollback of install restores manifest absence", async (t) => {
|
|
1700
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1701
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1702
|
+
const manager = managerFixture(sourceRoot);
|
|
1703
|
+
await manager.run("install", { targetRoot });
|
|
1704
|
+
await manager.run("rollback", { targetRoot });
|
|
1705
|
+
assert.equal(fs.existsSync(path.join(targetRoot, ".oak", "manifest.json")), false);
|
|
1706
|
+
});
|
|
1707
|
+
|
|
1708
|
+
test("[S100] rollback of uninstall restores the prior manifest", async (t) => {
|
|
1709
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1710
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1711
|
+
const manager = managerFixture(sourceRoot);
|
|
1712
|
+
await manager.run("install", { targetRoot });
|
|
1713
|
+
const before = fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
1714
|
+
await manager.run("uninstall", { targetRoot, yes: true });
|
|
1715
|
+
await manager.run("rollback", { targetRoot });
|
|
1716
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json")), before);
|
|
1717
|
+
});
|
|
1718
|
+
|
|
1719
|
+
test("[S131] committed rollback rejects manifest presence mismatch before inverse writes", async (t) => {
|
|
1720
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1721
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1722
|
+
const manager = managerFixture(sourceRoot);
|
|
1723
|
+
await manager.run("install", { targetRoot });
|
|
1724
|
+
fs.unlinkSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
1725
|
+
const result = await manager.run("rollback", { targetRoot });
|
|
1726
|
+
assert.equal(result.exitCode, 1);
|
|
1727
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), true);
|
|
1728
|
+
});
|
|
1729
|
+
|
|
1730
|
+
test("[S132] committed rollback rejects wrong current manifest digest", async (t) => {
|
|
1731
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1732
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1733
|
+
const manager = managerFixture(sourceRoot);
|
|
1734
|
+
await manager.run("install", { targetRoot });
|
|
1735
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1736
|
+
manifest.updated_at = "2026-07-21T00:00:00.000Z";
|
|
1737
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "manifest.json"), canonicalManifestBytes(manifest));
|
|
1738
|
+
const result = await manager.run("rollback", { targetRoot });
|
|
1739
|
+
assert.equal(result.exitCode, 1);
|
|
1740
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), true);
|
|
1741
|
+
});
|
|
1742
|
+
|
|
1743
|
+
test("[S029] interruption after managed rename but before progress publication remains recoverable", async (t) => {
|
|
1744
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1745
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
1746
|
+
put(targetRoot, "agents/lead.md", "old\n");
|
|
1747
|
+
await managerFixture(sourceRoot, {
|
|
1748
|
+
transactionId: () => "tx-interrupted",
|
|
1749
|
+
failpoint(name) { if (name === "after-operation-write-before-progress") throw new Error("lost parent fsync acknowledgement"); },
|
|
1750
|
+
}).run("install", { targetRoot, force: true });
|
|
1751
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "new\n");
|
|
1752
|
+
const result = await managerFixture(sourceRoot).run("rollback", { targetRoot });
|
|
1753
|
+
assert.equal(result.exitCode, 0);
|
|
1754
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "old\n");
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
test("[S030] failure while publishing a new rollback point preserves the previous point", async (t) => {
|
|
1758
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1759
|
+
put(sourceRoot, "agents/lead.md", "v1\n");
|
|
1760
|
+
await managerFixture(sourceRoot, { transactionId: () => "tx-install" }).run("install", { targetRoot });
|
|
1761
|
+
const prior = fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json"));
|
|
1762
|
+
put(sourceRoot, "agents/lead.md", "v2\n");
|
|
1763
|
+
await managerFixture(sourceRoot, {
|
|
1764
|
+
versionProvider: () => "1.0.28",
|
|
1765
|
+
transactionId: () => "tx-upgrade",
|
|
1766
|
+
failpoint(name) { if (name === "after-rollback-publication") throw new Error("crash"); },
|
|
1767
|
+
}).run("upgrade", { targetRoot });
|
|
1768
|
+
const recovered = await managerFixture(sourceRoot).run("rollback", { targetRoot });
|
|
1769
|
+
assert.equal(recovered.exitCode, 0);
|
|
1770
|
+
assert.deepEqual(fs.readFileSync(path.join(targetRoot, ".oak", "rollback", "transaction.json")), prior);
|
|
1771
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "v1\n");
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
test("[S048] bootstrap removal interruption still completes required sync and zero-state cleanup", async (t) => {
|
|
1775
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1776
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1777
|
+
const seen = [];
|
|
1778
|
+
await managerFixture(sourceRoot, {
|
|
1779
|
+
failpoint(name) {
|
|
1780
|
+
seen.push(name);
|
|
1781
|
+
if (name === "before-journal-create" || name === "after-bootstrap-oak-rmdir") throw new Error(name);
|
|
1782
|
+
},
|
|
1783
|
+
}).run("install", { targetRoot });
|
|
1784
|
+
assert.equal(seen.includes("after-bootstrap-oak-rmdir"), true);
|
|
1785
|
+
assert.equal(fs.existsSync(targetRoot), false);
|
|
1786
|
+
});
|
|
1787
|
+
|
|
1788
|
+
test("[S050] recovery resumes only remaining inverse operations after interruption", async (t) => {
|
|
1789
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1790
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
1791
|
+
put(targetRoot, "agents/lead.md", "old\n");
|
|
1792
|
+
await managerFixture(sourceRoot, {
|
|
1793
|
+
transactionId: () => "tx-forward",
|
|
1794
|
+
failpoint(name) { if (name === "after-operation-progress") throw new Error("forward crash"); },
|
|
1795
|
+
}).run("install", { targetRoot, force: true });
|
|
1796
|
+
const firstRecovery = await managerFixture(sourceRoot, {
|
|
1797
|
+
failpoint(name) { if (name === "after-inverse-write-before-progress") throw new Error("inverse crash"); },
|
|
1798
|
+
}).run("rollback", { targetRoot });
|
|
1799
|
+
assert.equal(firstRecovery.exitCode, 2);
|
|
1800
|
+
const resumed = await managerFixture(sourceRoot).run("rollback", { targetRoot });
|
|
1801
|
+
assert.equal(resumed.exitCode, 0);
|
|
1802
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "old\n");
|
|
1803
|
+
});
|
|
1804
|
+
|
|
1805
|
+
test("[S051] interrupted committed rollback resumes with matching rollback lock snapshot", async (t) => {
|
|
1806
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1807
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1808
|
+
const manager = managerFixture(sourceRoot, { transactionId: () => "tx-install" });
|
|
1809
|
+
await manager.run("install", { targetRoot });
|
|
1810
|
+
const interrupted = await managerFixture(sourceRoot, {
|
|
1811
|
+
failpoint(name) { if (name === "after-rollback-journal") throw new Error("rollback crash"); },
|
|
1812
|
+
}).run("rollback", { targetRoot });
|
|
1813
|
+
assert.equal(interrupted.exitCode, 2);
|
|
1814
|
+
const active = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "transaction.json"), "utf8"));
|
|
1815
|
+
const lock = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "lock.json"), "utf8"));
|
|
1816
|
+
assert.equal(active.lock.transaction_id, lock.transaction_id);
|
|
1817
|
+
assert.equal(active.lock.command, "rollback");
|
|
1818
|
+
assert.equal((await managerFixture(sourceRoot).run("rollback", { targetRoot })).exitCode, 0);
|
|
1819
|
+
|
|
1820
|
+
const successor = makeFixture(t);
|
|
1821
|
+
put(successor.sourceRoot, "agents/lead.md", "lead\n");
|
|
1822
|
+
await managerFixture(successor.sourceRoot, {
|
|
1823
|
+
transactionId: () => "tx-successor",
|
|
1824
|
+
failpoint(name) { if (name === "after-journal-create") throw new Error("forward crash"); },
|
|
1825
|
+
}).run("install", { targetRoot: successor.targetRoot });
|
|
1826
|
+
const successorLock = {
|
|
1827
|
+
transaction_id: "tx-successor",
|
|
1828
|
+
pid: 9876,
|
|
1829
|
+
command: "rollback",
|
|
1830
|
+
created_at: "2026-07-20T00:01:00.000Z",
|
|
1831
|
+
};
|
|
1832
|
+
fs.writeFileSync(path.join(successor.targetRoot, ".oak", "lock.json"), `${JSON.stringify(successorLock)}\n`);
|
|
1833
|
+
const recovered = await managerFixture(successor.sourceRoot, { pidProbe: () => ({ alive: false, code: "ESRCH" }) }).run("rollback", {
|
|
1834
|
+
targetRoot: successor.targetRoot,
|
|
1835
|
+
});
|
|
1836
|
+
assert.equal(recovered.exitCode, 0);
|
|
1837
|
+
assert.equal(fs.existsSync(path.join(successor.targetRoot, ".oak", "transaction.json")), false);
|
|
1838
|
+
});
|
|
1839
|
+
|
|
1840
|
+
test("[S053] acknowledgement aborts when target changes after confirmation", async (t) => {
|
|
1841
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1842
|
+
const result = await managerFixture(sourceRoot, {
|
|
1843
|
+
stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream,
|
|
1844
|
+
failpoint(name) { if (name === "after-ack-confirmation") fs.writeFileSync(path.join(targetRoot, "opencode.json"), "race\n"); },
|
|
1845
|
+
}).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1846
|
+
assert.equal(result.exitCode, 1);
|
|
1847
|
+
});
|
|
1848
|
+
|
|
1849
|
+
test("[S054] acknowledgement aborts when source changes after confirmation", async (t) => {
|
|
1850
|
+
const { sourceRoot, targetRoot, source, target } = preservedFixture(t);
|
|
1851
|
+
const result = await managerFixture(sourceRoot, {
|
|
1852
|
+
stdin: Readable.from([`${ackLine(source, target)}\n`]), stdout: capture().stream,
|
|
1853
|
+
failpoint(name) { if (name === "after-ack-confirmation") fs.writeFileSync(path.join(sourceRoot, "opencode.json"), "race\n"); },
|
|
1854
|
+
}).run("doctor", { targetRoot, acceptPreserved: "opencode.json" });
|
|
1855
|
+
assert.equal(result.exitCode, 1);
|
|
1856
|
+
});
|
|
1857
|
+
|
|
1858
|
+
test("[S058] interrupted-forward recovery resolves backup only from rollback.next", async (t) => {
|
|
1859
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1860
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
1861
|
+
put(targetRoot, "agents/lead.md", "old\n");
|
|
1862
|
+
await managerFixture(sourceRoot, {
|
|
1863
|
+
transactionId: () => "tx-forward",
|
|
1864
|
+
failpoint(name) { if (name === "after-operation-progress") throw new Error("crash"); },
|
|
1865
|
+
}).run("install", { targetRoot, force: true });
|
|
1866
|
+
fs.mkdirSync(path.join(targetRoot, ".oak", "rollback", "files"), { recursive: true });
|
|
1867
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "rollback", "files", "000000"), "wrong-root\n");
|
|
1868
|
+
await managerFixture(sourceRoot).run("rollback", { targetRoot });
|
|
1869
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "old\n");
|
|
1870
|
+
});
|
|
1871
|
+
|
|
1872
|
+
test("[S059] committed rollback resolves backup only from rollback", async (t) => {
|
|
1873
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1874
|
+
put(sourceRoot, "agents/lead.md", "new\n");
|
|
1875
|
+
put(targetRoot, "agents/lead.md", "old\n");
|
|
1876
|
+
const manager = managerFixture(sourceRoot);
|
|
1877
|
+
await manager.run("install", { targetRoot, force: true });
|
|
1878
|
+
fs.mkdirSync(path.join(targetRoot, ".oak", "rollback.next", "files"), { recursive: true });
|
|
1879
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "rollback.next", "files", "000000"), "wrong-root\n");
|
|
1880
|
+
await manager.run("rollback", { targetRoot });
|
|
1881
|
+
assert.equal(fs.readFileSync(path.join(targetRoot, "agents/lead.md"), "utf8"), "old\n");
|
|
1882
|
+
});
|
|
1883
|
+
|
|
1884
|
+
test("[S060] inconsistent rollback origin and status fail validation", () => {
|
|
1885
|
+
const transaction = validTransaction();
|
|
1886
|
+
transaction.status = "rolling-back";
|
|
1887
|
+
transaction.rollback_origin = "none";
|
|
1888
|
+
assert.throws(() => validateTransaction(transaction), /status.*rollback_origin/i);
|
|
1889
|
+
});
|
|
1890
|
+
|
|
1891
|
+
test("[S093] post-commit residue never supersedes the active rollback point", async (t) => {
|
|
1892
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1893
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1894
|
+
const committed = await managerFixture(sourceRoot, {
|
|
1895
|
+
failpoint(name) { if (name === "after-commit-boundary") throw new Error("cleanup crash"); },
|
|
1896
|
+
}).run("install", { targetRoot });
|
|
1897
|
+
assert.equal(committed.exitCode, 2);
|
|
1898
|
+
const doctor = await managerFixture(sourceRoot).run("doctor", { targetRoot });
|
|
1899
|
+
assert.equal(doctor.exitCode, 1);
|
|
1900
|
+
assert.equal(doctor.report.rollbackAvailable, true);
|
|
1901
|
+
assert.equal((await managerFixture(sourceRoot).run("rollback", { targetRoot })).exitCode, 0);
|
|
1902
|
+
assert.equal(fs.existsSync(path.join(targetRoot, "agents/lead.md")), false);
|
|
1903
|
+
});
|
|
1904
|
+
|
|
1905
|
+
test("[S101] recovery rejects manifest presence when recorded phase expects absence", async (t) => {
|
|
1906
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1907
|
+
put(sourceRoot, "agents/lead.md", "lead\n");
|
|
1908
|
+
await managerFixture(sourceRoot, { failpoint(name) { if (name === "after-journal-create") throw new Error("crash"); } }).run("install", { targetRoot });
|
|
1909
|
+
const journal = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "transaction.json"), "utf8"));
|
|
1910
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "manifest.json"), canonicalManifestBytes(journal.next_manifest));
|
|
1911
|
+
assert.equal((await managerFixture(sourceRoot).run("rollback", { targetRoot })).exitCode, 2);
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1914
|
+
test("[S102] recovery rejects manifest absence when recorded phase expects presence", async (t) => {
|
|
1915
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1916
|
+
put(sourceRoot, "agents/lead.md", "v1\n");
|
|
1917
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1918
|
+
put(sourceRoot, "agents/lead.md", "v2\n");
|
|
1919
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.28", transactionId: () => "tx-upgrade", failpoint(name) { if (name === "after-journal-create") throw new Error("crash"); } }).run("upgrade", { targetRoot });
|
|
1920
|
+
fs.unlinkSync(path.join(targetRoot, ".oak", "manifest.json"));
|
|
1921
|
+
assert.equal((await managerFixture(sourceRoot).run("rollback", { targetRoot })).exitCode, 2);
|
|
1922
|
+
});
|
|
1923
|
+
|
|
1924
|
+
test("[S133] recovery rejects wrong canonical manifest digest for its recorded phase", async (t) => {
|
|
1925
|
+
const { sourceRoot, targetRoot } = makeFixture(t);
|
|
1926
|
+
put(sourceRoot, "agents/lead.md", "v1\n");
|
|
1927
|
+
await managerFixture(sourceRoot).run("install", { targetRoot });
|
|
1928
|
+
put(sourceRoot, "agents/lead.md", "v2\n");
|
|
1929
|
+
await managerFixture(sourceRoot, { versionProvider: () => "1.0.28", transactionId: () => "tx-upgrade", failpoint(name) { if (name === "after-journal-create") throw new Error("crash"); } }).run("upgrade", { targetRoot });
|
|
1930
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(targetRoot, ".oak", "manifest.json"), "utf8"));
|
|
1931
|
+
manifest.updated_at = "2026-07-22T00:00:00.000Z";
|
|
1932
|
+
fs.writeFileSync(path.join(targetRoot, ".oak", "manifest.json"), canonicalManifestBytes(manifest));
|
|
1933
|
+
assert.equal((await managerFixture(sourceRoot).run("rollback", { targetRoot })).exitCode, 2);
|
|
1934
|
+
});
|
|
1935
|
+
|
|
1936
|
+
export { deterministicDeps, makeFixture };
|