@indigoai-us/hq-cloud 6.15.0 → 6.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/sync-mutation.d.ts +16 -0
- package/dist/bin/sync-mutation.d.ts.map +1 -0
- package/dist/bin/sync-mutation.js +60 -0
- package/dist/bin/sync-mutation.js.map +1 -0
- package/dist/bin/sync-mutation.test.d.ts +2 -0
- package/dist/bin/sync-mutation.test.d.ts.map +1 -0
- package/dist/bin/sync-mutation.test.js +165 -0
- package/dist/bin/sync-mutation.test.js.map +1 -0
- package/dist/bin/sync-runner-company.d.ts +8 -0
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +16 -0
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-company.test.d.ts +2 -0
- package/dist/bin/sync-runner-company.test.d.ts.map +1 -0
- package/dist/bin/sync-runner-company.test.js +36 -0
- package/dist/bin/sync-runner-company.test.js.map +1 -0
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +98 -8
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +17 -0
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +109 -0
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/conflict-recovery.test.d.ts +2 -0
- package/dist/cli/conflict-recovery.test.d.ts.map +1 -0
- package/dist/cli/conflict-recovery.test.js +201 -0
- package/dist/cli/conflict-recovery.test.js.map +1 -0
- package/dist/cli/conflict.d.ts +60 -0
- package/dist/cli/conflict.d.ts.map +1 -1
- package/dist/cli/conflict.js +333 -0
- package/dist/cli/conflict.js.map +1 -1
- package/dist/cli/sync.d.ts +35 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +100 -0
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +85 -1
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/skill-telemetry.d.ts +6 -0
- package/dist/skill-telemetry.d.ts.map +1 -1
- package/dist/skill-telemetry.js +14 -2
- package/dist/skill-telemetry.js.map +1 -1
- package/dist/skill-telemetry.test.js +79 -0
- package/dist/skill-telemetry.test.js.map +1 -1
- package/dist/sync/candidate-uploader.d.ts +88 -0
- package/dist/sync/candidate-uploader.d.ts.map +1 -0
- package/dist/sync/candidate-uploader.js +212 -0
- package/dist/sync/candidate-uploader.js.map +1 -0
- package/dist/sync/candidate-uploader.test.d.ts +2 -0
- package/dist/sync/candidate-uploader.test.d.ts.map +1 -0
- package/dist/sync/candidate-uploader.test.js +132 -0
- package/dist/sync/candidate-uploader.test.js.map +1 -0
- package/dist/sync/delta-client.d.ts +73 -0
- package/dist/sync/delta-client.d.ts.map +1 -0
- package/dist/sync/delta-client.js +201 -0
- package/dist/sync/delta-client.js.map +1 -0
- package/dist/sync/delta-client.test.d.ts +2 -0
- package/dist/sync/delta-client.test.d.ts.map +1 -0
- package/dist/sync/delta-client.test.js +97 -0
- package/dist/sync/delta-client.test.js.map +1 -0
- package/dist/sync/durable-apply.d.ts +76 -0
- package/dist/sync/durable-apply.d.ts.map +1 -0
- package/dist/sync/durable-apply.js +530 -0
- package/dist/sync/durable-apply.js.map +1 -0
- package/dist/sync/durable-apply.test.d.ts +2 -0
- package/dist/sync/durable-apply.test.d.ts.map +1 -0
- package/dist/sync/durable-apply.test.js +180 -0
- package/dist/sync/durable-apply.test.js.map +1 -0
- package/dist/sync/event-sync.d.ts +33 -1
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +149 -1
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/event-sync.test.js +142 -1
- package/dist/sync/event-sync.test.js.map +1 -1
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/multipart-uploader.d.ts +99 -0
- package/dist/sync/multipart-uploader.d.ts.map +1 -0
- package/dist/sync/multipart-uploader.js +447 -0
- package/dist/sync/multipart-uploader.js.map +1 -0
- package/dist/sync/multipart-uploader.test.d.ts +2 -0
- package/dist/sync/multipart-uploader.test.d.ts.map +1 -0
- package/dist/sync/multipart-uploader.test.js +119 -0
- package/dist/sync/multipart-uploader.test.js.map +1 -0
- package/dist/sync/mutation-client.d.ts +85 -0
- package/dist/sync/mutation-client.d.ts.map +1 -0
- package/dist/sync/mutation-client.js +245 -0
- package/dist/sync/mutation-client.js.map +1 -0
- package/dist/sync/mutation-client.test.d.ts +2 -0
- package/dist/sync/mutation-client.test.d.ts.map +1 -0
- package/dist/sync/mutation-client.test.js +51 -0
- package/dist/sync/mutation-client.test.js.map +1 -0
- package/dist/sync/push-receiver.d.ts +45 -0
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +101 -0
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +54 -2
- package/dist/sync/push-receiver.test.js.map +1 -1
- package/dist/sync/scope-inventory-client.d.ts +69 -0
- package/dist/sync/scope-inventory-client.d.ts.map +1 -0
- package/dist/sync/scope-inventory-client.js +210 -0
- package/dist/sync/scope-inventory-client.js.map +1 -0
- package/dist/sync/scope-inventory-client.test.d.ts +2 -0
- package/dist/sync/scope-inventory-client.test.d.ts.map +1 -0
- package/dist/sync/scope-inventory-client.test.js +94 -0
- package/dist/sync/scope-inventory-client.test.js.map +1 -0
- package/dist/sync/snapshot-client.d.ts +98 -0
- package/dist/sync/snapshot-client.d.ts.map +1 -0
- package/dist/sync/snapshot-client.js +402 -0
- package/dist/sync/snapshot-client.js.map +1 -0
- package/dist/sync/snapshot-client.test.d.ts +2 -0
- package/dist/sync/snapshot-client.test.d.ts.map +1 -0
- package/dist/sync/snapshot-client.test.js +169 -0
- package/dist/sync/snapshot-client.test.js.map +1 -0
- package/dist/sync/uploader-finalization.d.ts +97 -0
- package/dist/sync/uploader-finalization.d.ts.map +1 -0
- package/dist/sync/uploader-finalization.js +273 -0
- package/dist/sync/uploader-finalization.js.map +1 -0
- package/dist/sync/uploader-finalization.test.d.ts +2 -0
- package/dist/sync/uploader-finalization.test.d.ts.map +1 -0
- package/dist/sync/uploader-finalization.test.js +92 -0
- package/dist/sync/uploader-finalization.test.js.map +1 -0
- package/dist/telemetry.d.ts +11 -1
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +21 -2
- package/dist/telemetry.js.map +1 -1
- package/dist/telemetry.test.js +80 -0
- package/dist/telemetry.test.js.map +1 -1
- package/package.json +6 -1
- package/.claude/policies/hq-cloud-esm-cannot-spy-fs-builtins.md +0 -30
- package/.claude/policies/hq-cloud-strip-types-no-parameter-properties.md +0 -22
- package/.github/workflows/ci.yml +0 -84
- package/.github/workflows/publish.yml +0 -56
- package/.github/workflows/unreleased-commits-nag.yml +0 -256
- package/eslint.config.js +0 -67
- package/pnpm-workspace.yaml +0 -2
- package/scripts/presign-transport-e2e.mjs +0 -250
- package/scripts/vault-rebaseline.sh +0 -323
- package/scripts/vault-rescue.sh +0 -332
- package/src/active-company.test.ts +0 -188
- package/src/active-company.ts +0 -168
- package/src/agent-codex-instructions.test.ts +0 -332
- package/src/agent-codex-instructions.ts +0 -309
- package/src/auth.ts +0 -146
- package/src/backup-prune.test.ts +0 -98
- package/src/backup-prune.ts +0 -182
- package/src/bin/backup-prune-runner.ts +0 -33
- package/src/bin/rescue-runner.ts +0 -25
- package/src/bin/sync-runner-company.ts +0 -695
- package/src/bin/sync-runner-events.test.ts +0 -143
- package/src/bin/sync-runner-events.ts +0 -55
- package/src/bin/sync-runner-planning.test.ts +0 -311
- package/src/bin/sync-runner-planning.ts +0 -258
- package/src/bin/sync-runner-rollup.test.ts +0 -37
- package/src/bin/sync-runner-rollup.ts +0 -97
- package/src/bin/sync-runner-telemetry.ts +0 -15
- package/src/bin/sync-runner-watch-loop.ts +0 -1235
- package/src/bin/sync-runner-watch-routes.test.ts +0 -71
- package/src/bin/sync-runner-watch-routes.ts +0 -184
- package/src/bin/sync-runner.test.ts +0 -8767
- package/src/bin/sync-runner.ts +0 -2190
- package/src/cli/accept.ts +0 -124
- package/src/cli/conflict.ts +0 -119
- package/src/cli/doctor.test.ts +0 -581
- package/src/cli/doctor.ts +0 -642
- package/src/cli/index.ts +0 -49
- package/src/cli/invite.test.ts +0 -250
- package/src/cli/invite.ts +0 -214
- package/src/cli/promote.ts +0 -157
- package/src/cli/reindex-knowledge.test.ts +0 -307
- package/src/cli/reindex-knowledge.ts +0 -450
- package/src/cli/reindex.test.ts +0 -957
- package/src/cli/reindex.ts +0 -979
- package/src/cli/rescue-classify-ordering.test.ts +0 -548
- package/src/cli/rescue-clone-diagnostics.test.ts +0 -120
- package/src/cli/rescue-core.ts +0 -3011
- package/src/cli/rescue-drift-reconcile.test.ts +0 -179
- package/src/cli/rescue-drop-dir-symlink.test.ts +0 -224
- package/src/cli/rescue-exec-bit-preserve.test.ts +0 -187
- package/src/cli/rescue-hq-root-guard.test.ts +0 -232
- package/src/cli/rescue-journal-reconcile.test.ts +0 -215
- package/src/cli/rescue-mtime-preserve.test.ts +0 -203
- package/src/cli/rescue-settings-reconcile.test.ts +0 -637
- package/src/cli/rescue-snapshot.test.ts +0 -57
- package/src/cli/rescue-snapshot.ts +0 -51
- package/src/cli/rescue.reindex.test.ts +0 -63
- package/src/cli/rescue.test.ts +0 -131
- package/src/cli/rescue.ts +0 -182
- package/src/cli/share.test.ts +0 -7843
- package/src/cli/share.ts +0 -3663
- package/src/cli/sync-scope.test.ts +0 -652
- package/src/cli/sync.test.ts +0 -5207
- package/src/cli/sync.ts +0 -3470
- package/src/cli/tombstones.ts +0 -106
- package/src/cli/watch-event-push-conflict.test.ts +0 -234
- package/src/client-info.test.ts +0 -214
- package/src/client-info.ts +0 -121
- package/src/cognito-auth.test.ts +0 -712
- package/src/cognito-auth.ts +0 -1422
- package/src/company-resolver.test.ts +0 -618
- package/src/company-resolver.ts +0 -521
- package/src/context.test.ts +0 -583
- package/src/context.ts +0 -378
- package/src/daemon-worker.ts +0 -26
- package/src/daemon.ts +0 -99
- package/src/entity-resolver.test.ts +0 -315
- package/src/entity-resolver.ts +0 -180
- package/src/ignore.test.ts +0 -466
- package/src/ignore.ts +0 -469
- package/src/index.ts +0 -439
- package/src/journal.test.ts +0 -968
- package/src/journal.ts +0 -765
- package/src/lib/cloud-authoritative.test.ts +0 -45
- package/src/lib/cloud-authoritative.ts +0 -59
- package/src/lib/conflict-file.ts +0 -86
- package/src/lib/conflict-index.ts +0 -289
- package/src/lib/conflict.test.ts +0 -348
- package/src/lib/describe-error.test.ts +0 -100
- package/src/lib/describe-error.ts +0 -58
- package/src/lib/exit-codes.ts +0 -24
- package/src/lib/machine-id.test.ts +0 -231
- package/src/lib/machine-id.ts +0 -175
- package/src/lib/net-errors.test.ts +0 -65
- package/src/lib/net-errors.ts +0 -86
- package/src/lib/readlink-safe.test.ts +0 -43
- package/src/lib/readlink-safe.ts +0 -29
- package/src/local-path-codec.test.ts +0 -138
- package/src/local-path-codec.ts +0 -161
- package/src/machine-auth.test.ts +0 -1323
- package/src/manifest-reconcile.test.ts +0 -1123
- package/src/manifest-reconcile.ts +0 -518
- package/src/object-io.test.ts +0 -1221
- package/src/object-io.ts +0 -1306
- package/src/operation-lock.test.ts +0 -484
- package/src/operation-lock.ts +0 -680
- package/src/outcome-telemetry.test.ts +0 -498
- package/src/outcome-telemetry.ts +0 -639
- package/src/personal-vault-exclusions.test.ts +0 -308
- package/src/personal-vault-exclusions.ts +0 -354
- package/src/personal-vault.test.ts +0 -756
- package/src/personal-vault.ts +0 -496
- package/src/prefix-coalesce.test.ts +0 -240
- package/src/prefix-coalesce.ts +0 -273
- package/src/public-surface.test.ts +0 -117
- package/src/qmd-reindex.test.ts +0 -877
- package/src/qmd-reindex.ts +0 -842
- package/src/read-only-state-dir.test.ts +0 -188
- package/src/remote-pull.test.ts +0 -1130
- package/src/remote-pull.ts +0 -618
- package/src/s3.symlink-materialize.test.ts +0 -492
- package/src/s3.test.ts +0 -1789
- package/src/s3.ts +0 -1532
- package/src/schemas/signal-types.test.ts +0 -82
- package/src/schemas/signal-types.ts +0 -38
- package/src/schemas/source-channels.test.ts +0 -82
- package/src/schemas/source-channels.ts +0 -53
- package/src/scope-shrink.test.ts +0 -633
- package/src/scope-shrink.ts +0 -481
- package/src/signals/get.test.ts +0 -310
- package/src/signals/get.ts +0 -75
- package/src/signals/internals.ts +0 -195
- package/src/signals/list.test.ts +0 -420
- package/src/signals/list.ts +0 -79
- package/src/signals/parse.ts +0 -8
- package/src/signals/types.ts +0 -91
- package/src/skill-telemetry.test.ts +0 -1825
- package/src/skill-telemetry.ts +0 -1439
- package/src/sources/get.test.ts +0 -293
- package/src/sources/get.ts +0 -66
- package/src/sources/internals.ts +0 -198
- package/src/sources/list.test.ts +0 -402
- package/src/sources/list.ts +0 -84
- package/src/sources/parse.ts +0 -43
- package/src/sources/types.ts +0 -84
- package/src/sync/event-sync.test.ts +0 -594
- package/src/sync/event-sync.ts +0 -545
- package/src/sync/feature-flags.test.ts +0 -378
- package/src/sync/feature-flags.ts +0 -62
- package/src/sync/index.ts +0 -76
- package/src/sync/lease-client.test.ts +0 -128
- package/src/sync/lease-client.ts +0 -207
- package/src/sync/logger.test.ts +0 -242
- package/src/sync/logger.ts +0 -79
- package/src/sync/metrics.test.ts +0 -462
- package/src/sync/metrics.ts +0 -213
- package/src/sync/pull-scope.ts +0 -265
- package/src/sync/push-event.test.ts +0 -266
- package/src/sync/push-event.ts +0 -224
- package/src/sync/push-receiver.test.ts +0 -566
- package/src/sync/push-receiver.ts +0 -1048
- package/src/sync/push-transport.ts +0 -231
- package/src/sync/realtime-rollout.test.ts +0 -86
- package/src/sync/realtime-rollout.ts +0 -262
- package/src/sync/state-store.test.ts +0 -194
- package/src/sync/state-store.ts +0 -727
- package/src/sync-core.ts +0 -58
- package/src/sync-progress.test.ts +0 -94
- package/src/sync-progress.ts +0 -140
- package/src/telemetry-events.test.ts +0 -88
- package/src/telemetry-events.ts +0 -205
- package/src/telemetry.test.ts +0 -1280
- package/src/telemetry.ts +0 -1109
- package/src/types.ts +0 -314
- package/src/vault-client.test.ts +0 -1380
- package/src/vault-client.ts +0 -1694
- package/src/version.ts +0 -24
- package/src/watch-roots.test.ts +0 -278
- package/src/watch-roots.ts +0 -162
- package/src/watcher-event-gate.test.ts +0 -212
- package/src/watcher.test.ts +0 -1079
- package/src/watcher.ts +0 -1741
- package/test/e2e/sync/cross-tenant-isolation.test.ts +0 -630
- package/test/e2e/sync/skill-telemetry-oversized-transcript.test.ts +0 -124
- package/test/e2e/sync/transient-company-leg.test.ts +0 -384
- package/test/e2e/sync/windows-unreadable-link-leg.test.ts +0 -191
- package/test/e2e/watcher-real-chokidar.test.ts +0 -165
- package/test/e2e/watcher-recursive-backend.test.ts +0 -181
- package/test/e2e/watcher-scoped-coverage.test.ts +0 -381
- package/test/invite-flow.integration.test.ts +0 -244
- package/test/joiner-manifest-reconcile.integration.test.ts +0 -322
- package/test/share-sync.integration.test.ts +0 -213
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -22
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Regression test for the rescue HQ-root sanity gate in src/cli/rescue-core.ts.
|
|
3
|
-
*
|
|
4
|
-
* Bug (DEV-1741): the gate required BOTH `companies/` AND `personal/`. The
|
|
5
|
-
* `personal/` directory was only introduced in v15 — a faithful v14.0.0 install
|
|
6
|
-
* ships NEITHER `personal/` NOR `core/` (its scaffold lived in top-level dirs
|
|
7
|
-
* like `scripts/`, `workers/`, `knowledge/`, plus `.claude/`). So every v14.0.0
|
|
8
|
-
* user hit `error: ... missing companies/ or personal/. Aborting.` (exit 3) and
|
|
9
|
-
* had no supported upgrade path to v15.
|
|
10
|
-
*
|
|
11
|
-
* The gate now anchors on `companies/` plus ANY ONE of `.claude/`, `core/`, or
|
|
12
|
-
* `personal/`. `.claude/` exists on every release from v14 through v15, so the
|
|
13
|
-
* relaxed gate admits the full upgrade range while still rejecting a directory
|
|
14
|
-
* that is not an HQ root at all.
|
|
15
|
-
*
|
|
16
|
-
* Like the sibling drift test, the rescue clones its source from GitHub, so we
|
|
17
|
-
* shim `git clone` to a local fixture repo. All runs are `--dry-run` (no
|
|
18
|
-
* destructive ops, no backup) and we assert on the gate's behavior (exit code +
|
|
19
|
-
* message), not the full overlay.
|
|
20
|
-
*/
|
|
21
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
22
|
-
import { execFileSync } from "child_process";
|
|
23
|
-
import * as fs from "fs";
|
|
24
|
-
import * as os from "os";
|
|
25
|
-
import * as path from "path";
|
|
26
|
-
import { isUsableRescueRoot, runRescue } from "./rescue-core.js";
|
|
27
|
-
|
|
28
|
-
function hasGit(): boolean {
|
|
29
|
-
try {
|
|
30
|
-
execFileSync("git", ["--version"], { stdio: "ignore" });
|
|
31
|
-
return true;
|
|
32
|
-
} catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const gitAvailable = hasGit();
|
|
38
|
-
|
|
39
|
-
/** Run the rescue in-process, capturing its stdout/stderr. */
|
|
40
|
-
function runRescueCapture(argv: string[], env: NodeJS.ProcessEnv) {
|
|
41
|
-
let stdout = "";
|
|
42
|
-
let stderr = "";
|
|
43
|
-
const origOut = process.stdout.write.bind(process.stdout);
|
|
44
|
-
const origErr = process.stderr.write.bind(process.stderr);
|
|
45
|
-
process.stdout.write = ((chunk: unknown) => {
|
|
46
|
-
stdout += String(chunk);
|
|
47
|
-
return true;
|
|
48
|
-
}) as typeof process.stdout.write;
|
|
49
|
-
process.stderr.write = ((chunk: unknown) => {
|
|
50
|
-
stderr += String(chunk);
|
|
51
|
-
return true;
|
|
52
|
-
}) as typeof process.stderr.write;
|
|
53
|
-
let status: number;
|
|
54
|
-
try {
|
|
55
|
-
status = runRescue(argv, { env }).status;
|
|
56
|
-
} finally {
|
|
57
|
-
process.stdout.write = origOut;
|
|
58
|
-
process.stderr.write = origErr;
|
|
59
|
-
}
|
|
60
|
-
return { status, stdout, stderr };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
describe.skipIf(!gitAvailable)("rescue HQ-root sanity gate", () => {
|
|
64
|
-
let workDir: string;
|
|
65
|
-
let upstream: string;
|
|
66
|
-
let shimDir: string;
|
|
67
|
-
let floorSha: string;
|
|
68
|
-
let env: NodeJS.ProcessEnv;
|
|
69
|
-
|
|
70
|
-
const git = (cwd: string, ...args: string[]) =>
|
|
71
|
-
execFileSync("git", args, {
|
|
72
|
-
cwd,
|
|
73
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
74
|
-
env: {
|
|
75
|
-
...process.env,
|
|
76
|
-
GIT_AUTHOR_NAME: "t",
|
|
77
|
-
GIT_AUTHOR_EMAIL: "t@t",
|
|
78
|
-
GIT_COMMITTER_NAME: "t",
|
|
79
|
-
GIT_COMMITTER_EMAIL: "t@t",
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
.toString()
|
|
83
|
-
.trim();
|
|
84
|
-
|
|
85
|
-
beforeAll(() => {
|
|
86
|
-
workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-gate-"));
|
|
87
|
-
|
|
88
|
-
// --- Minimal local "upstream" repo (one core file, floor + HEAD). ---
|
|
89
|
-
upstream = path.join(workDir, "upstream");
|
|
90
|
-
fs.mkdirSync(path.join(upstream, "core"), { recursive: true });
|
|
91
|
-
git(workDir, "init", "-b", "main", "upstream");
|
|
92
|
-
fs.writeFileSync(path.join(upstream, "core/x.md"), "v1\n");
|
|
93
|
-
git(upstream, "add", "-A");
|
|
94
|
-
git(upstream, "commit", "-m", "floor");
|
|
95
|
-
floorSha = git(upstream, "rev-parse", "HEAD");
|
|
96
|
-
fs.writeFileSync(path.join(upstream, "core/x.md"), "v2\n");
|
|
97
|
-
git(upstream, "add", "-A");
|
|
98
|
-
git(upstream, "commit", "-m", "head");
|
|
99
|
-
|
|
100
|
-
// --- git shim: rewrite `git clone <github-url> dest` to the fixture. ---
|
|
101
|
-
const realGit =
|
|
102
|
-
execFileSync("bash", ["-lc", "command -v git"]).toString().trim() || "/usr/bin/git";
|
|
103
|
-
shimDir = path.join(workDir, "shim");
|
|
104
|
-
fs.mkdirSync(shimDir, { recursive: true });
|
|
105
|
-
const shim = `#!/usr/bin/env bash
|
|
106
|
-
if [ "$1" = "clone" ]; then
|
|
107
|
-
args=()
|
|
108
|
-
for a in "$@"; do
|
|
109
|
-
case "$a" in
|
|
110
|
-
https://github.com/*) a=${JSON.stringify(upstream)} ;;
|
|
111
|
-
esac
|
|
112
|
-
args+=("$a")
|
|
113
|
-
done
|
|
114
|
-
exec ${JSON.stringify(realGit)} "\${args[@]}"
|
|
115
|
-
fi
|
|
116
|
-
exec ${JSON.stringify(realGit)} "$@"
|
|
117
|
-
`;
|
|
118
|
-
fs.writeFileSync(path.join(shimDir, "git"), shim, { mode: 0o755 });
|
|
119
|
-
env = { ...process.env, PATH: `${shimDir}:${process.env.PATH ?? ""}` };
|
|
120
|
-
}, 60_000); // git init + commits can exceed vitest's 10s default under parallel load
|
|
121
|
-
|
|
122
|
-
afterAll(() => {
|
|
123
|
-
if (workDir) fs.rmSync(workDir, { recursive: true, force: true });
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
function makeRoot(name: string, dirs: string[]): string {
|
|
127
|
-
const root = path.join(workDir, name);
|
|
128
|
-
for (const d of dirs) fs.mkdirSync(path.join(root, d), { recursive: true });
|
|
129
|
-
return root;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function rescueDry(hqRoot: string) {
|
|
133
|
-
return runRescueCapture(
|
|
134
|
-
[
|
|
135
|
-
"--hq-root", hqRoot,
|
|
136
|
-
"--source", "test/repo",
|
|
137
|
-
"--ref", "main",
|
|
138
|
-
"--floor-sha", floorSha,
|
|
139
|
-
"--dry-run",
|
|
140
|
-
"--yes",
|
|
141
|
-
"--no-backup",
|
|
142
|
-
],
|
|
143
|
-
env,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
it("admits a faithful v14.0.0 root (companies/ + .claude/, NO personal/, NO core/)", () => {
|
|
148
|
-
// Exactly the shape that aborted before the fix.
|
|
149
|
-
const root = makeRoot("v14", ["companies", ".claude", "repos", "workspace"]);
|
|
150
|
-
expect(fs.existsSync(path.join(root, "personal"))).toBe(false);
|
|
151
|
-
expect(fs.existsSync(path.join(root, "core"))).toBe(false);
|
|
152
|
-
|
|
153
|
-
const r = rescueDry(root);
|
|
154
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
155
|
-
// Must get PAST the gate — not the exit-3 abort.
|
|
156
|
-
expect(r.status, out).not.toBe(3);
|
|
157
|
-
expect(out).not.toContain("does not look like an HQ root");
|
|
158
|
-
expect(r.status, out).toBe(0);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("admits a v15 root (companies/ + core/ + personal/)", () => {
|
|
162
|
-
const root = makeRoot("v15", ["companies", ".claude", "core", "personal", "repos", "workspace"]);
|
|
163
|
-
const r = rescueDry(root);
|
|
164
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
165
|
-
expect(r.status, out).toBe(0);
|
|
166
|
-
expect(out).not.toContain("does not look like an HQ root");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("admits a core-only root (companies/ + core/, no .claude/ or personal/)", () => {
|
|
170
|
-
const root = makeRoot("coreonly", ["companies", "core"]);
|
|
171
|
-
const r = rescueDry(root);
|
|
172
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
173
|
-
expect(r.status, out).not.toBe(3);
|
|
174
|
-
expect(out).not.toContain("does not look like an HQ root");
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("still rejects a non-HQ directory (companies/ only — no scaffold marker)", () => {
|
|
178
|
-
const root = makeRoot("bare", ["companies"]);
|
|
179
|
-
const r = rescueDry(root);
|
|
180
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
181
|
-
expect(r.status, out).toBe(3);
|
|
182
|
-
expect(out).toContain("does not look like an HQ root");
|
|
183
|
-
expect(out).toContain("need companies/ plus one of .claude/, core/, or personal/");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("still rejects a directory with a marker but no companies/", () => {
|
|
187
|
-
const root = makeRoot("nocompanies", [".claude", "core", "personal"]);
|
|
188
|
-
const r = rescueDry(root);
|
|
189
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
190
|
-
expect(r.status, out).toBe(3);
|
|
191
|
-
expect(out).toContain("does not look like an HQ root");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// 2026-08-02 Windows field failure: `--hq-root C:` (a path mangled upstream
|
|
195
|
-
// of this process) crashed with an uncaught EISDIR from fs.realpathSync on
|
|
196
|
-
// every daily background attempt. The gate must fail CLOSED — clean exit 1,
|
|
197
|
-
// no throw — and echo the received argv so the log identifies the caller.
|
|
198
|
-
it("rejects a bare drive letter --hq-root with a clean exit and argv echo", () => {
|
|
199
|
-
const r = rescueDry("C:");
|
|
200
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
201
|
-
expect(r.status, out).toBe(1);
|
|
202
|
-
expect(out).toContain("--hq-root must be an absolute path");
|
|
203
|
-
expect(out).toContain('"C:"');
|
|
204
|
-
expect(out).toContain("argv:");
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("rejects a relative --hq-root with a clean exit", () => {
|
|
208
|
-
const r = rescueDry("some/relative/dir");
|
|
209
|
-
const out = `${r.stdout}\n${r.stderr}`;
|
|
210
|
-
expect(r.status, out).toBe(1);
|
|
211
|
-
expect(out).toContain("--hq-root must be an absolute path");
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe("isUsableRescueRoot (pure)", () => {
|
|
216
|
-
it("rejects bare drive letters under both path flavors", () => {
|
|
217
|
-
expect(isUsableRescueRoot("C:", path.win32)).toBe(false);
|
|
218
|
-
expect(isUsableRescueRoot("z:", path.win32)).toBe(false);
|
|
219
|
-
expect(isUsableRescueRoot("C:", path.posix)).toBe(false);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it("accepts absolute roots for the matching platform", () => {
|
|
223
|
-
expect(isUsableRescueRoot("C:\\Users\\caio\\HQ", path.win32)).toBe(true);
|
|
224
|
-
expect(isUsableRescueRoot("/Users/caio/HQ", path.posix)).toBe(true);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("rejects relative and drive-relative paths", () => {
|
|
228
|
-
expect(isUsableRescueRoot("Users\\caio\\HQ", path.win32)).toBe(false);
|
|
229
|
-
expect(isUsableRescueRoot("C:Users\\caio\\HQ", path.win32)).toBe(false);
|
|
230
|
-
expect(isUsableRescueRoot("some/dir", path.posix)).toBe(false);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Regression for the rescue <-> sync-journal interaction (6.2.4 semantics).
|
|
3
|
-
*
|
|
4
|
-
* History: 6.2.1/6.2.3 "reconciled" the journal after a rescue by re-stamping
|
|
5
|
-
* changed scaffold entries to the current local hash. That MASKED the rescue's
|
|
6
|
-
* changes from the sync engine: the push leg saw localChanged=false and never
|
|
7
|
-
* uploaded the regenerated scaffold, so the vault silently kept stale bytes
|
|
8
|
-
* while the journal claimed convergence (verified live 2026-06-10: 4 scaffold
|
|
9
|
-
* files byte-diverged from the vault under a 0-conflict sync).
|
|
10
|
-
*
|
|
11
|
-
* Correct semantics (this test): the rescue must NOT touch the personal-vault
|
|
12
|
-
* sync journal at all. Rescue-changed scaffold stays visible as "local
|
|
13
|
-
* changed", the next bidirectional sync pushes it up, and the pull-side
|
|
14
|
-
* byte-identical convergence probe (6.2.0) absorbs cross-machine races.
|
|
15
|
-
*
|
|
16
|
-
* Also covered: the core/core.yaml provenance stamp must be DETERMINISTIC —
|
|
17
|
-
* a pure function of the source SHA (committer time, not wall-clock now) — so
|
|
18
|
-
* every machine rescuing the same release writes byte-identical core.yaml.
|
|
19
|
-
* The wall-clock stamp was the one genuine cross-machine divergence engine
|
|
20
|
-
* behind `core.yaml.conflict-*` mirrors.
|
|
21
|
-
*/
|
|
22
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
23
|
-
import { execFileSync } from "child_process";
|
|
24
|
-
import * as fs from "fs";
|
|
25
|
-
import * as os from "os";
|
|
26
|
-
import * as path from "path";
|
|
27
|
-
import { runRescue } from "./rescue-core.js";
|
|
28
|
-
import {
|
|
29
|
-
hashFile,
|
|
30
|
-
readJournal,
|
|
31
|
-
writeJournal,
|
|
32
|
-
PERSONAL_VAULT_JOURNAL_SLUG,
|
|
33
|
-
} from "../journal.js";
|
|
34
|
-
|
|
35
|
-
function hasGit(): boolean {
|
|
36
|
-
try {
|
|
37
|
-
execFileSync("git", ["--version"], { stdio: "ignore" });
|
|
38
|
-
return true;
|
|
39
|
-
} catch {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const gitAvailable = hasGit();
|
|
44
|
-
|
|
45
|
-
function runRescueCapture(argv: string[], env: NodeJS.ProcessEnv) {
|
|
46
|
-
let stdout = "";
|
|
47
|
-
const origOut = process.stdout.write.bind(process.stdout);
|
|
48
|
-
const origErr = process.stderr.write.bind(process.stderr);
|
|
49
|
-
process.stdout.write = ((c: unknown) => ((stdout += String(c)), true)) as typeof process.stdout.write;
|
|
50
|
-
process.stderr.write = (() => true) as typeof process.stderr.write;
|
|
51
|
-
let status: number;
|
|
52
|
-
try {
|
|
53
|
-
status = runRescue(argv, { env }).status;
|
|
54
|
-
} finally {
|
|
55
|
-
process.stdout.write = origOut;
|
|
56
|
-
process.stderr.write = origErr;
|
|
57
|
-
}
|
|
58
|
-
return { status, stdout };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const SCAFFOLD = ["core/a.md", "core/docs/b.md", ".claude/c.sh", "core/core.yaml"];
|
|
62
|
-
|
|
63
|
-
describe.skipIf(!gitAvailable)("rescue leaves the sync journal untouched + stamps core.yaml deterministically", () => {
|
|
64
|
-
let workDir: string, upstream: string, hqRoot: string, stateDir: string, floorSha: string;
|
|
65
|
-
let env: NodeJS.ProcessEnv;
|
|
66
|
-
let savedStateDir: string | undefined;
|
|
67
|
-
let headCommitterIso: string;
|
|
68
|
-
let seededHashes: Record<string, string>;
|
|
69
|
-
|
|
70
|
-
const git = (cwd: string, ...args: string[]) =>
|
|
71
|
-
execFileSync("git", args, {
|
|
72
|
-
cwd,
|
|
73
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
74
|
-
env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" },
|
|
75
|
-
}).toString().trim();
|
|
76
|
-
|
|
77
|
-
const w = (root: string, rel: string, body: string) => {
|
|
78
|
-
const p = path.join(root, rel);
|
|
79
|
-
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
80
|
-
fs.writeFileSync(p, body);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
beforeAll(() => {
|
|
84
|
-
workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-journal-"));
|
|
85
|
-
|
|
86
|
-
// --- upstream: floor (all scaffold = v1), HEAD advances the 3 docs to v2 ---
|
|
87
|
-
upstream = path.join(workDir, "upstream");
|
|
88
|
-
fs.mkdirSync(upstream, { recursive: true });
|
|
89
|
-
git(workDir, "init", "-b", "main", "upstream");
|
|
90
|
-
w(upstream, "core/a.md", "v1\n");
|
|
91
|
-
w(upstream, "core/docs/b.md", "v1\n");
|
|
92
|
-
w(upstream, ".claude/c.sh", "v1\n");
|
|
93
|
-
w(upstream, "core/core.yaml", "version: 1\n");
|
|
94
|
-
git(upstream, "add", "-A"); git(upstream, "commit", "-m", "floor");
|
|
95
|
-
floorSha = git(upstream, "rev-parse", "HEAD");
|
|
96
|
-
w(upstream, "core/a.md", "v2\n");
|
|
97
|
-
w(upstream, "core/docs/b.md", "v2\n");
|
|
98
|
-
w(upstream, ".claude/c.sh", "v2\n");
|
|
99
|
-
git(upstream, "add", "-A"); git(upstream, "commit", "-m", "head");
|
|
100
|
-
headCommitterIso = git(upstream, "show", "-s", "--format=%cI", "HEAD");
|
|
101
|
-
|
|
102
|
-
// --- local HQ root: scaffold == floor (overlaid to v2); a pending personal/ edit ---
|
|
103
|
-
hqRoot = path.join(workDir, "hq");
|
|
104
|
-
fs.mkdirSync(path.join(hqRoot, "companies"), { recursive: true });
|
|
105
|
-
w(hqRoot, "core/a.md", "v1\n");
|
|
106
|
-
w(hqRoot, "core/docs/b.md", "v1\n");
|
|
107
|
-
w(hqRoot, ".claude/c.sh", "v1\n");
|
|
108
|
-
w(hqRoot, "core/core.yaml", "version: 1\n");
|
|
109
|
-
w(hqRoot, "personal/edited.md", "USER_LOCAL\n"); // local pending edit
|
|
110
|
-
|
|
111
|
-
// --- state dir + seeded journal: pre-rescue baselines for scaffold + a divergent personal/ entry ---
|
|
112
|
-
stateDir = path.join(workDir, "state");
|
|
113
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
114
|
-
savedStateDir = process.env.HQ_STATE_DIR;
|
|
115
|
-
process.env.HQ_STATE_DIR = stateDir;
|
|
116
|
-
const entry = (rel: string, hash: string) => ({
|
|
117
|
-
hash,
|
|
118
|
-
size: fs.statSync(path.join(hqRoot, rel)).size,
|
|
119
|
-
syncedAt: new Date(0).toISOString(),
|
|
120
|
-
direction: "down" as const,
|
|
121
|
-
remoteEtag: "seed-etag",
|
|
122
|
-
mtimeMs: fs.statSync(path.join(hqRoot, rel)).mtimeMs,
|
|
123
|
-
});
|
|
124
|
-
const files: Record<string, unknown> = {};
|
|
125
|
-
seededHashes = {};
|
|
126
|
-
for (const rel of SCAFFOLD) {
|
|
127
|
-
const h = hashFile(path.join(hqRoot, rel)); // hash of v1/version:1
|
|
128
|
-
seededHashes[rel] = h;
|
|
129
|
-
files[rel] = entry(rel, h);
|
|
130
|
-
}
|
|
131
|
-
// personal/ pending edit: journal records a DIFFERENT (already-synced) hash than local.
|
|
132
|
-
files["personal/edited.md"] = { ...entry("personal/edited.md", "remote-side-hash-differs-from-local") };
|
|
133
|
-
writeJournal(PERSONAL_VAULT_JOURNAL_SLUG, {
|
|
134
|
-
version: "2", lastSync: new Date(0).toISOString(), files, pulls: [],
|
|
135
|
-
} as never);
|
|
136
|
-
|
|
137
|
-
// --- git shim: redirect clone to the local fixture ---
|
|
138
|
-
const realGit = execFileSync("bash", ["-lc", "command -v git"]).toString().trim() || "/usr/bin/git";
|
|
139
|
-
const shimDir = path.join(workDir, "shim");
|
|
140
|
-
fs.mkdirSync(shimDir, { recursive: true });
|
|
141
|
-
fs.writeFileSync(
|
|
142
|
-
path.join(shimDir, "git"),
|
|
143
|
-
`#!/usr/bin/env bash
|
|
144
|
-
if [ "$1" = "clone" ]; then
|
|
145
|
-
args=(); for a in "$@"; do case "$a" in https://github.com/*) a=${JSON.stringify(upstream)} ;; esac; args+=("$a"); done
|
|
146
|
-
exec ${JSON.stringify(realGit)} "\${args[@]}"
|
|
147
|
-
fi
|
|
148
|
-
exec ${JSON.stringify(realGit)} "$@"
|
|
149
|
-
`,
|
|
150
|
-
{ mode: 0o755 },
|
|
151
|
-
);
|
|
152
|
-
env = { ...process.env, PATH: `${shimDir}:${process.env.PATH ?? ""}`, HQ_STATE_DIR: stateDir };
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
afterAll(() => {
|
|
156
|
-
if (savedStateDir === undefined) delete process.env.HQ_STATE_DIR;
|
|
157
|
-
else process.env.HQ_STATE_DIR = savedStateDir;
|
|
158
|
-
if (workDir) fs.rmSync(workDir, { recursive: true, force: true });
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("leaves EVERY journal entry untouched so the push leg uploads rescue output (vault converges)", () => {
|
|
162
|
-
const r = runRescueCapture(
|
|
163
|
-
["--hq-root", hqRoot, "--source", "test/repo", "--ref", "main", "--floor-sha", floorSha, "--yes", "--no-backup"],
|
|
164
|
-
env,
|
|
165
|
-
);
|
|
166
|
-
expect(r.status, r.stdout).toBe(0);
|
|
167
|
-
|
|
168
|
-
// the 3 docs were overlaid v1 -> v2
|
|
169
|
-
for (const rel of ["core/a.md", "core/docs/b.md", ".claude/c.sh"]) {
|
|
170
|
-
expect(fs.readFileSync(path.join(hqRoot, rel), "utf-8")).toBe("v2\n");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const j = readJournal(PERSONAL_VAULT_JOURNAL_SLUG).files;
|
|
174
|
-
|
|
175
|
-
// INVARIANT: the rescue never rewrites journal baselines. Every scaffold
|
|
176
|
-
// entry still carries its PRE-rescue hash -> localChanged=true on the next
|
|
177
|
-
// sync -> the push leg uploads the regenerated scaffold and the VAULT
|
|
178
|
-
// converges to the rescue output. (Masking these — 6.2.1/6.2.3 — left the
|
|
179
|
-
// vault silently stale.)
|
|
180
|
-
for (const rel of SCAFFOLD) {
|
|
181
|
-
expect(j[rel].hash, `${rel} baseline was rewritten`).toBe(seededHashes[rel]);
|
|
182
|
-
expect(j[rel].remoteEtag, `${rel} remote side touched`).toBe("seed-etag");
|
|
183
|
-
// and the local file genuinely changed, so the entry is push-visible
|
|
184
|
-
expect(j[rel].hash).not.toBe(hashFile(path.join(hqRoot, rel)));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// SAFETY: the personal/ pending edit is untouched too — still uploads.
|
|
188
|
-
expect(j["personal/edited.md"].hash).toBe("remote-side-hash-differs-from-local");
|
|
189
|
-
expect(j["personal/edited.md"].hash).not.toBe(hashFile(path.join(hqRoot, "personal/edited.md")));
|
|
190
|
-
|
|
191
|
-
// the masking reconcile is gone
|
|
192
|
-
expect(r.stdout).not.toContain("Reconciled sync-journal baseline");
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("stamps core.yaml deterministically: byte-identical across runs, last_sync_at = source committer time", () => {
|
|
196
|
-
const coreYaml = path.join(hqRoot, "core/core.yaml");
|
|
197
|
-
const firstRun = fs.readFileSync(coreYaml, "utf-8");
|
|
198
|
-
|
|
199
|
-
// last_sync_at must be derived from the HEAD commit, not wall-clock now.
|
|
200
|
-
// utcStamp(_, "colon") renders UTC as YYYY-MM-DDTHH:MM:SSZ — compare on
|
|
201
|
-
// the epoch second, not the string, to stay offset-agnostic.
|
|
202
|
-
const stamped = /last_sync_at:\s*["']?([0-9TZ:.-]+)["']?/.exec(firstRun);
|
|
203
|
-
expect(stamped, `no last_sync_at in:\n${firstRun}`).not.toBeNull();
|
|
204
|
-
expect(new Date(stamped![1]).getTime()).toBe(new Date(headCommitterIso).getTime());
|
|
205
|
-
|
|
206
|
-
// a second rescue of the SAME SHA must write byte-identical core.yaml —
|
|
207
|
-
// this is the cross-machine `core.yaml.conflict-*` mirror regression.
|
|
208
|
-
const r2 = runRescueCapture(
|
|
209
|
-
["--hq-root", hqRoot, "--source", "test/repo", "--ref", "main", "--floor-sha", floorSha, "--yes", "--no-backup"],
|
|
210
|
-
env,
|
|
211
|
-
);
|
|
212
|
-
expect(r2.status, r2.stdout).toBe(0);
|
|
213
|
-
expect(fs.readFileSync(coreYaml, "utf-8")).toBe(firstRun);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration regression for the rescue mtime-preservation fix in
|
|
3
|
-
* src/cli/rescue-core.ts.
|
|
4
|
-
*
|
|
5
|
-
* The bug: rescue rebuilds the tree by `git clone` + `rsync -a`. A git
|
|
6
|
-
* checkout stamps every file with clone-time (git stores no per-file mtimes),
|
|
7
|
-
* so the overlay reset EVERY rescued file's mtime to "whenever rescue ran" —
|
|
8
|
-
* collapsing real history onto one instant (the exact fingerprint that flagged
|
|
9
|
-
* this: hundreds of files sharing one mtime, mtime == ctime == birth).
|
|
10
|
-
*
|
|
11
|
-
* The fix has three parts, all asserted below:
|
|
12
|
-
* - Layer 1: UNCHANGED files are left in place; the overlay excludes them, so
|
|
13
|
-
* their existing mtime survives.
|
|
14
|
-
* - Layer 2: files the overlay DOES write (upstream-changed, brand-new) get
|
|
15
|
-
* the git committer-date of their last-modifying commit, not wall-clock.
|
|
16
|
-
* - Layer 3: full history is used (history_floor mode clones full history;
|
|
17
|
-
* the shallow path unshallows) so per-file commit times are real.
|
|
18
|
-
*
|
|
19
|
-
* The rescue clones from GitHub, so we shim `git clone` to a local fixture
|
|
20
|
-
* (same technique as rescue-drift-reconcile.test.ts) and run for real
|
|
21
|
-
* (non-dry-run, --no-backup) so the overlay actually lays files down.
|
|
22
|
-
*/
|
|
23
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
24
|
-
import { execFileSync } from "child_process";
|
|
25
|
-
import * as fs from "fs";
|
|
26
|
-
import * as os from "os";
|
|
27
|
-
import * as path from "path";
|
|
28
|
-
import { runRescue } from "./rescue-core.js";
|
|
29
|
-
|
|
30
|
-
function has(bin: string, ...args: string[]): boolean {
|
|
31
|
-
try {
|
|
32
|
-
execFileSync(bin, args, { stdio: "ignore" });
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Needs git (fixture + clone) and rsync (overlay). The mtime restore is now
|
|
40
|
-
// native (fs.utimesSync), so perl is no longer required.
|
|
41
|
-
const toolsAvailable = has("git", "--version") && has("rsync", "--version");
|
|
42
|
-
|
|
43
|
-
// Fixed commit epochs so assertions are exact and machine-independent.
|
|
44
|
-
const FLOOR_EPOCH = 1577836800; // 2020-01-01T00:00:00Z
|
|
45
|
-
const HEAD_EPOCH = 1609459200; // 2021-01-01T00:00:00Z
|
|
46
|
-
const KEEP_PRESET_EPOCH = 1546300800; // 2019-01-01T00:00:00Z (local, pre-rescue)
|
|
47
|
-
|
|
48
|
-
/** Run the rescue in-process, capturing its stdout/stderr. */
|
|
49
|
-
function runRescueCapture(argv: string[], env: NodeJS.ProcessEnv) {
|
|
50
|
-
let stdout = "";
|
|
51
|
-
let stderr = "";
|
|
52
|
-
const origOut = process.stdout.write.bind(process.stdout);
|
|
53
|
-
const origErr = process.stderr.write.bind(process.stderr);
|
|
54
|
-
process.stdout.write = ((chunk: unknown) => {
|
|
55
|
-
stdout += String(chunk);
|
|
56
|
-
return true;
|
|
57
|
-
}) as typeof process.stdout.write;
|
|
58
|
-
process.stderr.write = ((chunk: unknown) => {
|
|
59
|
-
stderr += String(chunk);
|
|
60
|
-
return true;
|
|
61
|
-
}) as typeof process.stderr.write;
|
|
62
|
-
let status: number;
|
|
63
|
-
try {
|
|
64
|
-
status = runRescue(argv, { env }).status;
|
|
65
|
-
} finally {
|
|
66
|
-
process.stdout.write = origOut;
|
|
67
|
-
process.stderr.write = origErr;
|
|
68
|
-
}
|
|
69
|
-
return { status, stdout, stderr };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
describe.skipIf(!toolsAvailable)("rescue preserves mtimes (no clone-time flattening)", () => {
|
|
73
|
-
let workDir: string;
|
|
74
|
-
let upstream: string;
|
|
75
|
-
let hqRoot: string;
|
|
76
|
-
let shimDir: string;
|
|
77
|
-
let floorSha: string;
|
|
78
|
-
let env: NodeJS.ProcessEnv;
|
|
79
|
-
|
|
80
|
-
const gitAt = (cwd: string, epoch: number, ...args: string[]) =>
|
|
81
|
-
execFileSync("git", args, {
|
|
82
|
-
cwd,
|
|
83
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
84
|
-
env: {
|
|
85
|
-
...process.env,
|
|
86
|
-
GIT_AUTHOR_NAME: "t",
|
|
87
|
-
GIT_AUTHOR_EMAIL: "t@t",
|
|
88
|
-
GIT_COMMITTER_NAME: "t",
|
|
89
|
-
GIT_COMMITTER_EMAIL: "t@t",
|
|
90
|
-
GIT_AUTHOR_DATE: `${epoch} +0000`,
|
|
91
|
-
GIT_COMMITTER_DATE: `${epoch} +0000`,
|
|
92
|
-
},
|
|
93
|
-
})
|
|
94
|
-
.toString()
|
|
95
|
-
.trim();
|
|
96
|
-
|
|
97
|
-
const mtimeSec = (p: string) => Math.floor(fs.statSync(p).mtimeMs / 1000);
|
|
98
|
-
|
|
99
|
-
beforeAll(() => {
|
|
100
|
-
workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-mtime-"));
|
|
101
|
-
|
|
102
|
-
// --- "upstream" repo ----------------------------------------------------
|
|
103
|
-
// floor commit (2020): x.md=v1, edited.md=base, keep.md=same
|
|
104
|
-
// HEAD commit (2021): x.md=v2 (changed) + new.md added; keep.md untouched
|
|
105
|
-
upstream = path.join(workDir, "upstream");
|
|
106
|
-
fs.mkdirSync(path.join(upstream, "core"), { recursive: true });
|
|
107
|
-
gitAt(workDir, FLOOR_EPOCH, "init", "-b", "main", "upstream");
|
|
108
|
-
fs.writeFileSync(path.join(upstream, "core/x.md"), "v1\n");
|
|
109
|
-
fs.writeFileSync(path.join(upstream, "core/edited.md"), "base\n");
|
|
110
|
-
fs.writeFileSync(path.join(upstream, "core/keep.md"), "same\n");
|
|
111
|
-
gitAt(upstream, FLOOR_EPOCH, "add", "-A");
|
|
112
|
-
gitAt(upstream, FLOOR_EPOCH, "commit", "-m", "floor");
|
|
113
|
-
floorSha = gitAt(upstream, FLOOR_EPOCH, "rev-parse", "HEAD");
|
|
114
|
-
fs.writeFileSync(path.join(upstream, "core/x.md"), "v2\n");
|
|
115
|
-
fs.writeFileSync(path.join(upstream, "core/new.md"), "fresh\n");
|
|
116
|
-
gitAt(upstream, HEAD_EPOCH, "add", "-A");
|
|
117
|
-
gitAt(upstream, HEAD_EPOCH, "commit", "-m", "head");
|
|
118
|
-
|
|
119
|
-
// --- local HQ root being rescued ----------------------------------------
|
|
120
|
-
hqRoot = path.join(workDir, "hq");
|
|
121
|
-
fs.mkdirSync(path.join(hqRoot, "core"), { recursive: true });
|
|
122
|
-
fs.mkdirSync(path.join(hqRoot, "personal"), { recursive: true });
|
|
123
|
-
fs.mkdirSync(path.join(hqRoot, "companies"), { recursive: true });
|
|
124
|
-
// Unchanged vs floor but upstream advanced v1 -> v2: overlay rewrites it.
|
|
125
|
-
fs.writeFileSync(path.join(hqRoot, "core/x.md"), "v1\n");
|
|
126
|
-
// User-edited: rescued to personal/ (not asserted here).
|
|
127
|
-
fs.writeFileSync(path.join(hqRoot, "core/edited.md"), "MINE\n");
|
|
128
|
-
// Identical to upstream HEAD: UNCHANGED -> left in place. Pre-stamp an old
|
|
129
|
-
// mtime that must survive the rescue.
|
|
130
|
-
const keep = path.join(hqRoot, "core/keep.md");
|
|
131
|
-
fs.writeFileSync(keep, "same\n");
|
|
132
|
-
fs.utimesSync(keep, KEEP_PRESET_EPOCH, KEEP_PRESET_EPOCH);
|
|
133
|
-
|
|
134
|
-
// --- git shim: redirect `git clone <github-url>` to the local fixture ----
|
|
135
|
-
const realGit = execFileSync("bash", ["-lc", "command -v git"]).toString().trim() || "/usr/bin/git";
|
|
136
|
-
shimDir = path.join(workDir, "shim");
|
|
137
|
-
fs.mkdirSync(shimDir, { recursive: true });
|
|
138
|
-
const shim = `#!/usr/bin/env bash
|
|
139
|
-
if [ "$1" = "clone" ]; then
|
|
140
|
-
args=()
|
|
141
|
-
for a in "$@"; do
|
|
142
|
-
case "$a" in
|
|
143
|
-
https://github.com/*) a=${JSON.stringify(upstream)} ;;
|
|
144
|
-
esac
|
|
145
|
-
args+=("$a")
|
|
146
|
-
done
|
|
147
|
-
exec ${JSON.stringify(realGit)} "\${args[@]}"
|
|
148
|
-
fi
|
|
149
|
-
exec ${JSON.stringify(realGit)} "$@"
|
|
150
|
-
`;
|
|
151
|
-
fs.writeFileSync(path.join(shimDir, "git"), shim, { mode: 0o755 });
|
|
152
|
-
env = { ...process.env, PATH: `${shimDir}:${process.env.PATH ?? ""}` };
|
|
153
|
-
|
|
154
|
-
// --- run the real rescue (non-dry-run) ----------------------------------
|
|
155
|
-
const r = runRescueCapture(
|
|
156
|
-
[
|
|
157
|
-
"--hq-root", hqRoot,
|
|
158
|
-
"--source", "test/repo",
|
|
159
|
-
"--ref", "main",
|
|
160
|
-
"--floor-sha", floorSha,
|
|
161
|
-
"--yes",
|
|
162
|
-
"--no-backup",
|
|
163
|
-
],
|
|
164
|
-
env,
|
|
165
|
-
);
|
|
166
|
-
// Surface output on failure for debuggability.
|
|
167
|
-
if (r.status !== 0) {
|
|
168
|
-
throw new Error(`rescue failed (${r.status}):\n${r.stdout}\n${r.stderr}`);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
afterAll(() => {
|
|
173
|
-
if (workDir) fs.rmSync(workDir, { recursive: true, force: true });
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("rewrites an upstream-changed file with its git commit mtime (not now)", () => {
|
|
177
|
-
const x = path.join(hqRoot, "core/x.md");
|
|
178
|
-
expect(fs.readFileSync(x, "utf-8")).toBe("v2\n");
|
|
179
|
-
expect(mtimeSec(x)).toBe(HEAD_EPOCH);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("creates a brand-new upstream file with its git commit mtime", () => {
|
|
183
|
-
const n = path.join(hqRoot, "core/new.md");
|
|
184
|
-
expect(fs.existsSync(n)).toBe(true);
|
|
185
|
-
expect(mtimeSec(n)).toBe(HEAD_EPOCH);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("leaves an UNCHANGED file in place, preserving its existing mtime (Layer 1)", () => {
|
|
189
|
-
const keep = path.join(hqRoot, "core/keep.md");
|
|
190
|
-
expect(fs.readFileSync(keep, "utf-8")).toBe("same\n");
|
|
191
|
-
expect(mtimeSec(keep)).toBe(KEEP_PRESET_EPOCH);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("never stamps an overlaid file with wall-clock-now (the original bug)", () => {
|
|
195
|
-
const now = Math.floor(Date.now() / 1000);
|
|
196
|
-
for (const rel of ["core/x.md", "core/new.md", "core/keep.md"]) {
|
|
197
|
-
const age = now - mtimeSec(path.join(hqRoot, rel));
|
|
198
|
-
// Every asserted file predates the run by years; a clone-time stamp
|
|
199
|
-
// would be within seconds of now.
|
|
200
|
-
expect(age, `${rel} mtime looks like wall-clock-now`).toBeGreaterThan(60);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|