@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
package/src/cli/doctor.test.ts
DELETED
|
@@ -1,581 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `hq sync doctor` (US-003,
|
|
3
|
-
* hq-sync-windows-skill-symlink-collision): skill-key family dedupe in the
|
|
4
|
-
* vault + junk-wrapper GC in the local `.claude/skills/` farm.
|
|
5
|
-
*
|
|
6
|
-
* The object store is dependency-injected (`SyncDoctorOptions.store`) with an
|
|
7
|
-
* in-memory fake, so no test touches a network or a real vault. Local-farm
|
|
8
|
-
* cases run against a mkdtemp root with real symlinks (the same approach as
|
|
9
|
-
* s3.symlink-materialize.test.ts) and pin win32 naming via the injectable
|
|
10
|
-
* `win32` option rather than the host platform.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
14
|
-
import * as fs from "fs";
|
|
15
|
-
import * as os from "os";
|
|
16
|
-
import * as path from "path";
|
|
17
|
-
import { syncDoctor, SKILLS_KEY_PREFIX, type DoctorStore } from "./doctor.js";
|
|
18
|
-
import type {
|
|
19
|
-
GetObjectResult,
|
|
20
|
-
ListObjectsInput,
|
|
21
|
-
ListObjectsResult,
|
|
22
|
-
PutObjectInput,
|
|
23
|
-
} from "../object-io.js";
|
|
24
|
-
import type { VaultServiceConfig } from "../types.js";
|
|
25
|
-
|
|
26
|
-
const vaultConfig: VaultServiceConfig = {
|
|
27
|
-
apiUrl: "https://vault-api.test",
|
|
28
|
-
authToken: "test-jwt-token",
|
|
29
|
-
region: "us-east-1",
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
interface FakeObject {
|
|
33
|
-
body: Buffer;
|
|
34
|
-
lastModified: Date;
|
|
35
|
-
metadata?: Record<string, string>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* In-memory DoctorStore. Pages listings two keys at a time so the doctor's
|
|
40
|
-
* continuation-token loop is exercised by every test, and records every
|
|
41
|
-
* mutation so dry-run tests can assert "nothing was written".
|
|
42
|
-
*/
|
|
43
|
-
class FakeStore implements DoctorStore {
|
|
44
|
-
readonly objects = new Map<string, FakeObject>();
|
|
45
|
-
readonly puts: string[] = [];
|
|
46
|
-
readonly deletes: string[] = [];
|
|
47
|
-
|
|
48
|
-
set(key: string, body: string, lastModified: string, metadata?: Record<string, string>): void {
|
|
49
|
-
this.objects.set(key, {
|
|
50
|
-
body: Buffer.from(body, "utf-8"),
|
|
51
|
-
lastModified: new Date(lastModified),
|
|
52
|
-
metadata,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async listObjects(input: ListObjectsInput): Promise<ListObjectsResult> {
|
|
57
|
-
const keys = [...this.objects.keys()]
|
|
58
|
-
.filter((k) => k.startsWith(input.prefix ?? ""))
|
|
59
|
-
.sort();
|
|
60
|
-
const start = input.continuationToken ? Number(input.continuationToken) : 0;
|
|
61
|
-
const page = keys.slice(start, start + 2);
|
|
62
|
-
return {
|
|
63
|
-
objects: page.map((key) => ({
|
|
64
|
-
key,
|
|
65
|
-
size: this.objects.get(key)!.body.length,
|
|
66
|
-
lastModified: this.objects.get(key)!.lastModified,
|
|
67
|
-
etag: `"etag-${key}"`,
|
|
68
|
-
})),
|
|
69
|
-
nextContinuationToken:
|
|
70
|
-
start + 2 < keys.length ? String(start + 2) : undefined,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async getObject(key: string): Promise<GetObjectResult> {
|
|
75
|
-
const obj = this.objects.get(key);
|
|
76
|
-
if (!obj) throw new Error(`NoSuchKey: ${key}`);
|
|
77
|
-
return { body: obj.body, metadata: obj.metadata };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async putObject(input: PutObjectInput): Promise<{ etag: string }> {
|
|
81
|
-
this.puts.push(input.key);
|
|
82
|
-
this.objects.set(input.key, {
|
|
83
|
-
body: input.body,
|
|
84
|
-
lastModified: new Date(),
|
|
85
|
-
metadata: input.metadata,
|
|
86
|
-
});
|
|
87
|
-
return { etag: '"put-etag"' };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async deleteObject(key: string): Promise<void> {
|
|
91
|
-
this.deletes.push(key);
|
|
92
|
-
this.objects.delete(key);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const FARM = `${SKILLS_KEY_PREFIX}`;
|
|
97
|
-
|
|
98
|
-
describe("syncDoctor — vault skill-key dedupe", () => {
|
|
99
|
-
let tmpRoot: string;
|
|
100
|
-
let store: FakeStore;
|
|
101
|
-
|
|
102
|
-
beforeEach(() => {
|
|
103
|
-
tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-doctor-test-"));
|
|
104
|
-
store = new FakeStore();
|
|
105
|
-
// Keep the plan printer quiet in test output; assertions run against the
|
|
106
|
-
// returned result, not the console.
|
|
107
|
-
vi.spyOn(console, "log").mockImplementation(() => {});
|
|
108
|
-
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
afterEach(() => {
|
|
112
|
-
vi.restoreAllMocks();
|
|
113
|
-
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
114
|
-
delete process.env.HQ_SYNC_DELETE_BULK_OVERRIDE;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
function run(overrides: Partial<Parameters<typeof syncDoctor>[0]> = {}) {
|
|
118
|
-
return syncDoctor({
|
|
119
|
-
entity: "prs_TEST",
|
|
120
|
-
vaultConfig,
|
|
121
|
-
hqRoot: tmpRoot,
|
|
122
|
-
store,
|
|
123
|
-
win32: true,
|
|
124
|
-
...overrides,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
it("groups 3+ encoded generations into one canonical family and (re)writes the missing ':' key from the newest body", async () => {
|
|
129
|
-
// Three junk generations of the same logical wrapper, no canonical key.
|
|
130
|
-
// %3A -> %253A -> %25253A all decode (to fixpoint) to ':'.
|
|
131
|
-
store.set(`${FARM}eng%3Aarchitect/SKILL.md`, "hq-symlink:../a", "2026-07-01T00:00:00Z");
|
|
132
|
-
store.set(`${FARM}eng%253Aarchitect/SKILL.md`, "hq-symlink:../b", "2026-07-02T00:00:00Z");
|
|
133
|
-
store.set(`${FARM}eng%25253Aarchitect/SKILL.md`, "hq-symlink:../c", "2026-07-03T00:00:00Z");
|
|
134
|
-
|
|
135
|
-
const res = await run({ yes: true });
|
|
136
|
-
|
|
137
|
-
// One family; the newest-bodied spelling (%25253A generation) wins.
|
|
138
|
-
expect(res.plan.rewrites).toEqual([
|
|
139
|
-
{
|
|
140
|
-
key: `${FARM}eng:architect/SKILL.md`,
|
|
141
|
-
fromSpelling: `${FARM}eng%25253Aarchitect/SKILL.md`,
|
|
142
|
-
},
|
|
143
|
-
]);
|
|
144
|
-
expect(res.keysRewritten).toBe(1);
|
|
145
|
-
expect(
|
|
146
|
-
store.objects.get(`${FARM}eng:architect/SKILL.md`)!.body.toString("utf-8"),
|
|
147
|
-
).toBe("hq-symlink:../c");
|
|
148
|
-
// Every non-canonical spelling is tombstoned (marker bodies = safe).
|
|
149
|
-
expect(res.plan.tombstones.sort()).toEqual([
|
|
150
|
-
`${FARM}eng%25253Aarchitect/SKILL.md`,
|
|
151
|
-
`${FARM}eng%253Aarchitect/SKILL.md`,
|
|
152
|
-
`${FARM}eng%3Aarchitect/SKILL.md`,
|
|
153
|
-
]);
|
|
154
|
-
expect(res.keysDeleted).toBe(3);
|
|
155
|
-
expect([...store.objects.keys()]).toEqual([`${FARM}eng:architect/SKILL.md`]);
|
|
156
|
-
expect(res.plan.manualReview).toEqual([]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("newest-wins: a junk spelling newer than the canonical key rewrites the canonical body", async () => {
|
|
160
|
-
store.set(`${FARM}indigo:capture/scripts`, "hq-symlink:../old", "2026-07-01T00:00:00Z");
|
|
161
|
-
store.set(`${FARM}indigo%3Acapture/scripts`, "hq-symlink:../new", "2026-07-05T00:00:00Z");
|
|
162
|
-
|
|
163
|
-
const res = await run({ yes: true });
|
|
164
|
-
|
|
165
|
-
expect(res.plan.rewrites).toEqual([
|
|
166
|
-
{
|
|
167
|
-
key: `${FARM}indigo:capture/scripts`,
|
|
168
|
-
fromSpelling: `${FARM}indigo%3Acapture/scripts`,
|
|
169
|
-
},
|
|
170
|
-
]);
|
|
171
|
-
expect(
|
|
172
|
-
store.objects.get(`${FARM}indigo:capture/scripts`)!.body.toString("utf-8"),
|
|
173
|
-
).toBe("hq-symlink:../new");
|
|
174
|
-
expect(res.plan.tombstones).toEqual([`${FARM}indigo%3Acapture/scripts`]);
|
|
175
|
-
expect(store.objects.has(`${FARM}indigo%3Acapture/scripts`)).toBe(false);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("keeps an up-to-date canonical key untouched when its body is already the newest", async () => {
|
|
179
|
-
store.set(`${FARM}indigo:recall/SKILL.md`, "hq-symlink:../t", "2026-07-05T00:00:00Z");
|
|
180
|
-
store.set(`${FARM}indigo%3Arecall/SKILL.md`, "hq-symlink:../t", "2026-07-01T00:00:00Z");
|
|
181
|
-
|
|
182
|
-
const res = await run({ yes: true });
|
|
183
|
-
|
|
184
|
-
expect(res.plan.rewrites).toEqual([]);
|
|
185
|
-
expect(res.plan.keep).toContain(`${FARM}indigo:recall/SKILL.md`);
|
|
186
|
-
expect(store.puts).toEqual([]);
|
|
187
|
-
expect(res.plan.tombstones).toEqual([`${FARM}indigo%3Arecall/SKILL.md`]);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("safety gate: a non-marker body that differs from the canonical twin goes to manual review, never deleted", async () => {
|
|
191
|
-
// Canonical is newest (so the junk spelling is NOT the winner); the junk
|
|
192
|
-
// body is real content, not a symlink marker, and differs byte-wise.
|
|
193
|
-
store.set(`${FARM}indigo:notes/SKILL.md`, "canonical content", "2026-07-05T00:00:00Z");
|
|
194
|
-
store.set(`${FARM}indigo%3Anotes/SKILL.md`, "divergent real content", "2026-07-01T00:00:00Z");
|
|
195
|
-
|
|
196
|
-
const res = await run({ yes: true });
|
|
197
|
-
|
|
198
|
-
expect(res.plan.tombstones).toEqual([]);
|
|
199
|
-
expect(res.keysDeleted).toBe(0);
|
|
200
|
-
expect(res.plan.manualReview).toEqual([
|
|
201
|
-
{
|
|
202
|
-
key: `${FARM}indigo%3Anotes/SKILL.md`,
|
|
203
|
-
reason:
|
|
204
|
-
"body is neither a symlink marker nor byte-identical to the canonical key — not auto-deleted",
|
|
205
|
-
},
|
|
206
|
-
]);
|
|
207
|
-
// The divergent object is still in the store — surfaced, not removed.
|
|
208
|
-
expect(store.objects.has(`${FARM}indigo%3Anotes/SKILL.md`)).toBe(true);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("safety gate: a non-marker body byte-identical to the canonical twin IS safe to delete", async () => {
|
|
212
|
-
store.set(`${FARM}indigo:notes/SKILL.md`, "same real content", "2026-07-05T00:00:00Z");
|
|
213
|
-
store.set(`${FARM}indigo%3Anotes/SKILL.md`, "same real content", "2026-07-01T00:00:00Z");
|
|
214
|
-
|
|
215
|
-
const res = await run({ yes: true });
|
|
216
|
-
|
|
217
|
-
expect(res.plan.tombstones).toEqual([`${FARM}indigo%3Anotes/SKILL.md`]);
|
|
218
|
-
expect(res.keysDeleted).toBe(1);
|
|
219
|
-
expect(res.plan.manualReview).toEqual([]);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it("a body-fetch failure is a loud non-fatal skip: the spelling lands in manual review and the run continues", async () => {
|
|
223
|
-
store.set(`${FARM}indigo:ok/SKILL.md`, "hq-symlink:../t", "2026-07-05T00:00:00Z");
|
|
224
|
-
store.set(`${FARM}indigo%3Aok/SKILL.md`, "hq-symlink:../t", "2026-07-01T00:00:00Z");
|
|
225
|
-
const failingKey = `${FARM}indigo%253Aok/SKILL.md`;
|
|
226
|
-
store.set(failingKey, "hq-symlink:../t", "2026-07-02T00:00:00Z");
|
|
227
|
-
const realGet = store.getObject.bind(store);
|
|
228
|
-
vi.spyOn(store, "getObject").mockImplementation(async (key: string) => {
|
|
229
|
-
if (key === failingKey) throw new Error("simulated 500");
|
|
230
|
-
return realGet(key);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const res = await run({ yes: true });
|
|
234
|
-
|
|
235
|
-
expect(res.plan.manualReview).toEqual([
|
|
236
|
-
{ key: failingKey, reason: "body fetch failed — bytes unknown, not touched" },
|
|
237
|
-
]);
|
|
238
|
-
expect(res.warnings).toBeGreaterThan(0);
|
|
239
|
-
// The healthy sibling was still processed.
|
|
240
|
-
expect(res.plan.tombstones).toEqual([`${FARM}indigo%3Aok/SKILL.md`]);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("does not delete a family's tombstones when its canonical rewrite failed (the junk spelling may hold the only body)", async () => {
|
|
244
|
-
// Newest (only) body lives at the junk spelling; canonical key is absent,
|
|
245
|
-
// so applying requires rewrite-then-delete. Fail the rewrite: the delete
|
|
246
|
-
// leg must skip this family's tombstones or the only copy is lost.
|
|
247
|
-
store.set(`${FARM}eng%3Afoo/SKILL.md`, "hq-symlink:../only", "2026-07-01T00:00:00Z");
|
|
248
|
-
const put = store.putObject.bind(store);
|
|
249
|
-
vi.spyOn(store, "putObject").mockImplementation(async (input) => {
|
|
250
|
-
if (input.key === `${FARM}eng:foo/SKILL.md`) throw new Error("503 SlowDown");
|
|
251
|
-
return put(input);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
const res = await run({ yes: true });
|
|
255
|
-
|
|
256
|
-
expect(res.keysRewritten).toBe(0);
|
|
257
|
-
expect(res.keysDeleted).toBe(0);
|
|
258
|
-
expect(store.deletes).toEqual([]);
|
|
259
|
-
expect(store.objects.has(`${FARM}eng%3Afoo/SKILL.md`)).toBe(true);
|
|
260
|
-
expect(res.warnings).toBeGreaterThanOrEqual(2); // failed rewrite + skipped delete
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("colon-free percent spellings are their own canonical: no rewrite, no move, no delete (round-9)", async () => {
|
|
264
|
-
// A legitimate skill whose NAME contains a percent escape must never be
|
|
265
|
-
// 'collapsed' into the decoded name — that would move/delete real
|
|
266
|
-
// content. Both spellings coexist as independent keys.
|
|
267
|
-
store.set(`${FARM}foo%20bar/SKILL.md`, "real skill content", "2026-07-01T00:00:00Z");
|
|
268
|
-
store.set(`${FARM}foo bar/SKILL.md`, "a different real skill", "2026-07-01T00:00:00Z");
|
|
269
|
-
|
|
270
|
-
const res = await run({ yes: true });
|
|
271
|
-
|
|
272
|
-
expect(res.plan.rewrites).toEqual([]);
|
|
273
|
-
expect(res.plan.tombstones).toEqual([]);
|
|
274
|
-
expect(res.keysDeleted).toBe(0);
|
|
275
|
-
expect(store.objects.has(`${FARM}foo%20bar/SKILL.md`)).toBe(true);
|
|
276
|
-
expect(store.objects.has(`${FARM}foo bar/SKILL.md`)).toBe(true);
|
|
277
|
-
expect(res.plan.keep.sort()).toEqual([
|
|
278
|
-
`${FARM}foo bar/SKILL.md`,
|
|
279
|
-
`${FARM}foo%20bar/SKILL.md`,
|
|
280
|
-
]);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it("fences canonical rewrites with CAS: ifNoneMatch:'*' when absent, ifMatch:<listed etag> when stale", async () => {
|
|
284
|
-
store.set(`${FARM}eng%3Acasnew/SKILL.md`, "hq-symlink:../a", "2026-07-01T00:00:00Z");
|
|
285
|
-
store.set(`${FARM}eng:casstale/SKILL.md`, "hq-symlink:../old", "2026-07-01T00:00:00Z");
|
|
286
|
-
store.set(`${FARM}eng%3Acasstale/SKILL.md`, "hq-symlink:../new", "2026-07-02T00:00:00Z");
|
|
287
|
-
const putSpy = vi.spyOn(store, "putObject");
|
|
288
|
-
|
|
289
|
-
await run({ yes: true });
|
|
290
|
-
|
|
291
|
-
const puts = putSpy.mock.calls.map((c) => c[0]);
|
|
292
|
-
const created = puts.find((p) => p.key === `${FARM}eng:casnew/SKILL.md`)!;
|
|
293
|
-
expect(created.ifNoneMatch).toBe("*");
|
|
294
|
-
expect(created.ifMatch).toBeUndefined();
|
|
295
|
-
const updated = puts.find((p) => p.key === `${FARM}eng:casstale/SKILL.md`)!;
|
|
296
|
-
expect(updated.ifMatch).toBe(`"etag-${FARM}eng:casstale/SKILL.md"`);
|
|
297
|
-
expect(updated.ifNoneMatch).toBeUndefined();
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it("a 412 precondition failure on the rewrite keeps the family's tombstones (no clobber, no orphaned delete)", async () => {
|
|
301
|
-
store.set(`${FARM}eng:casrace/SKILL.md`, "hq-symlink:../old", "2026-07-01T00:00:00Z");
|
|
302
|
-
store.set(`${FARM}eng%3Acasrace/SKILL.md`, "hq-symlink:../new", "2026-07-02T00:00:00Z");
|
|
303
|
-
vi.spyOn(store, "putObject").mockImplementation(async () => {
|
|
304
|
-
throw Object.assign(new Error("PreconditionFailed"), { $metadata: { httpStatusCode: 412 } });
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const res = await run({ yes: true });
|
|
308
|
-
|
|
309
|
-
expect(res.keysRewritten).toBe(0);
|
|
310
|
-
expect(res.keysDeleted).toBe(0);
|
|
311
|
-
expect(store.objects.has(`${FARM}eng%3Acasrace/SKILL.md`)).toBe(true);
|
|
312
|
-
expect(res.warnings).toBeGreaterThanOrEqual(2);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("parks the whole family when the canonical body fetch fails — no rewrite from a junk sibling, no deletes", async () => {
|
|
316
|
-
// Round-4 review P1: a transient/403 canonical read must not let the
|
|
317
|
-
// newest junk sibling overwrite unknown canonical bytes.
|
|
318
|
-
store.set(`${FARM}eng:parked/SKILL.md`, "possibly-real user content", "2026-07-01T00:00:00Z");
|
|
319
|
-
store.set(`${FARM}eng%3Aparked/SKILL.md`, "hq-symlink:../newer", "2026-07-02T00:00:00Z");
|
|
320
|
-
const get = store.getObject.bind(store);
|
|
321
|
-
vi.spyOn(store, "getObject").mockImplementation(async (key) => {
|
|
322
|
-
if (key === `${FARM}eng:parked/SKILL.md`) throw new Error("403 slow down");
|
|
323
|
-
return get(key);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
const res = await run({ yes: true });
|
|
327
|
-
|
|
328
|
-
expect(res.plan.rewrites).toEqual([]);
|
|
329
|
-
expect(res.plan.tombstones).toEqual([]);
|
|
330
|
-
expect(res.keysRewritten).toBe(0);
|
|
331
|
-
expect(res.keysDeleted).toBe(0);
|
|
332
|
-
expect(res.plan.manualReview).toEqual(
|
|
333
|
-
expect.arrayContaining([
|
|
334
|
-
{
|
|
335
|
-
key: `${FARM}eng:parked/SKILL.md`,
|
|
336
|
-
reason: "body fetch failed — bytes unknown, not touched",
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
key: `${FARM}eng%3Aparked/SKILL.md`,
|
|
340
|
-
reason: "canonical body unknown (fetch failed) — family not touched",
|
|
341
|
-
},
|
|
342
|
-
]),
|
|
343
|
-
);
|
|
344
|
-
expect(store.objects.has(`${FARM}eng:parked/SKILL.md`)).toBe(true);
|
|
345
|
-
expect(store.objects.has(`${FARM}eng%3Aparked/SKILL.md`)).toBe(true);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it("bulk-asymmetry guard: a large delete plan is refused without an explicit override (policy sync-delete-bulk-asymmetry-guard)", async () => {
|
|
349
|
-
// 12 families, each canonical + one identical junk twin: 12 tombstones out
|
|
350
|
-
// of 24 in-scope keys (50% >= 10%, 12 >= 10) — the breaker must trip.
|
|
351
|
-
for (let i = 0; i < 12; i++) {
|
|
352
|
-
store.set(`${FARM}ns:skill-${i}/SKILL.md`, `hq-symlink:../${i}`, "2026-07-05T00:00:00Z");
|
|
353
|
-
store.set(`${FARM}ns%3Askill-${i}/SKILL.md`, `hq-symlink:../${i}`, "2026-07-01T00:00:00Z");
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const refused = await run({ yes: true });
|
|
357
|
-
expect(refused.plan.bulkRefused).toBe(true);
|
|
358
|
-
expect(refused.plan.tombstones).toHaveLength(12);
|
|
359
|
-
expect(refused.keysDeleted).toBe(0);
|
|
360
|
-
expect(store.deletes).toEqual([]);
|
|
361
|
-
|
|
362
|
-
// Explicit override flag applies the same plan.
|
|
363
|
-
const applied = await run({ yes: true, bulkDeleteOverride: true });
|
|
364
|
-
expect(applied.plan.bulkRefused).toBe(false);
|
|
365
|
-
expect(applied.keysDeleted).toBe(12);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it("bulk-asymmetry guard honors the HQ_SYNC_DELETE_BULK_OVERRIDE env rollback knob", async () => {
|
|
369
|
-
for (let i = 0; i < 12; i++) {
|
|
370
|
-
store.set(`${FARM}ns:skill-${i}/SKILL.md`, `hq-symlink:../${i}`, "2026-07-05T00:00:00Z");
|
|
371
|
-
store.set(`${FARM}ns%3Askill-${i}/SKILL.md`, `hq-symlink:../${i}`, "2026-07-01T00:00:00Z");
|
|
372
|
-
}
|
|
373
|
-
process.env.HQ_SYNC_DELETE_BULK_OVERRIDE = "1";
|
|
374
|
-
|
|
375
|
-
const res = await run({ yes: true });
|
|
376
|
-
expect(res.plan.bulkRefused).toBe(false);
|
|
377
|
-
expect(res.keysDeleted).toBe(12);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it("dry-run is the default: the full plan is produced and NOTHING is written", async () => {
|
|
381
|
-
store.set(`${FARM}eng%3Aarchitect/SKILL.md`, "hq-symlink:../a", "2026-07-01T00:00:00Z");
|
|
382
|
-
store.set(`${FARM}eng%253Aarchitect/SKILL.md`, "hq-symlink:../b", "2026-07-02T00:00:00Z");
|
|
383
|
-
// Junk local wrapper next to its canonical twin, GC-eligible.
|
|
384
|
-
const skillsDir = path.join(tmpRoot, ".claude", "skills");
|
|
385
|
-
fs.mkdirSync(path.join(skillsDir, "eng%3Aarchitect"), { recursive: true });
|
|
386
|
-
const junkDir = path.join(skillsDir, "eng%25253Aarchitect");
|
|
387
|
-
fs.mkdirSync(junkDir);
|
|
388
|
-
fs.writeFileSync(path.join(tmpRoot, "target.md"), "x");
|
|
389
|
-
fs.symlinkSync(path.join(tmpRoot, "target.md"), path.join(junkDir, "link.md"));
|
|
390
|
-
|
|
391
|
-
const res = await run(); // no `yes`
|
|
392
|
-
|
|
393
|
-
// Plan is fully populated…
|
|
394
|
-
expect(res.plan.rewrites).toHaveLength(1);
|
|
395
|
-
expect(res.plan.tombstones).toHaveLength(2);
|
|
396
|
-
expect(res.plan.localRemovals).toEqual([junkDir]);
|
|
397
|
-
// …but nothing was applied: no puts, no deletes, junk dir still on disk.
|
|
398
|
-
expect(res.applied).toBe(false);
|
|
399
|
-
expect(store.puts).toEqual([]);
|
|
400
|
-
expect(store.deletes).toEqual([]);
|
|
401
|
-
expect(store.objects.has(`${FARM}eng%3Aarchitect/SKILL.md`)).toBe(true);
|
|
402
|
-
expect(fs.existsSync(junkDir)).toBe(true);
|
|
403
|
-
expect(res.keysRewritten).toBe(0);
|
|
404
|
-
expect(res.keysDeleted).toBe(0);
|
|
405
|
-
expect(res.dirsRemoved).toBe(0);
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
describe("syncDoctor — local skill-farm GC", () => {
|
|
410
|
-
let tmpRoot: string;
|
|
411
|
-
let skillsDir: string;
|
|
412
|
-
let store: FakeStore;
|
|
413
|
-
|
|
414
|
-
beforeEach(() => {
|
|
415
|
-
tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-doctor-gc-test-"));
|
|
416
|
-
skillsDir = path.join(tmpRoot, ".claude", "skills");
|
|
417
|
-
fs.mkdirSync(skillsDir, { recursive: true });
|
|
418
|
-
store = new FakeStore();
|
|
419
|
-
vi.spyOn(console, "log").mockImplementation(() => {});
|
|
420
|
-
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
afterEach(() => {
|
|
424
|
-
vi.restoreAllMocks();
|
|
425
|
-
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
function run(overrides: Partial<Parameters<typeof syncDoctor>[0]> = {}) {
|
|
429
|
-
return syncDoctor({
|
|
430
|
-
entity: "prs_TEST",
|
|
431
|
-
vaultConfig,
|
|
432
|
-
hqRoot: tmpRoot,
|
|
433
|
-
store,
|
|
434
|
-
win32: true,
|
|
435
|
-
...overrides,
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/** Junk-named dir containing only symlinks — the 134-dirs incident shape. */
|
|
440
|
-
function makeSymlinkFarmDir(name: string): string {
|
|
441
|
-
const dir = path.join(skillsDir, name);
|
|
442
|
-
fs.mkdirSync(dir);
|
|
443
|
-
const target = path.join(tmpRoot, `${name}-target.md`);
|
|
444
|
-
fs.writeFileSync(target, "target");
|
|
445
|
-
fs.symlinkSync(target, path.join(dir, "link.md"));
|
|
446
|
-
return dir;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
it("removes a junk dir whose name decodes to a canonical wrapper that exists on disk (symlink content only)", async () => {
|
|
450
|
-
// The incident's exact shape: 'hq-pack-engineering%25253Aarchitect'
|
|
451
|
-
// decodes to 'hq-pack-engineering:architect', whose canonical win32
|
|
452
|
-
// wrapper 'hq-pack-engineering%3Aarchitect' already exists.
|
|
453
|
-
fs.mkdirSync(path.join(skillsDir, "hq-pack-engineering%3Aarchitect"));
|
|
454
|
-
const junk = makeSymlinkFarmDir("hq-pack-engineering%25253Aarchitect");
|
|
455
|
-
|
|
456
|
-
const res = await run({ yes: true });
|
|
457
|
-
|
|
458
|
-
expect(res.plan.localRemovals).toEqual([junk]);
|
|
459
|
-
expect(res.dirsRemoved).toBe(1);
|
|
460
|
-
expect(fs.existsSync(junk)).toBe(false);
|
|
461
|
-
// The canonical wrapper is untouched.
|
|
462
|
-
expect(fs.existsSync(path.join(skillsDir, "hq-pack-engineering%3Aarchitect"))).toBe(true);
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
it("refuses a junk dir that contains any real (non-symlink) file — manual review only", async () => {
|
|
466
|
-
fs.mkdirSync(path.join(skillsDir, "eng%3Aweb"));
|
|
467
|
-
const junk = path.join(skillsDir, "eng%253Aweb");
|
|
468
|
-
fs.mkdirSync(junk);
|
|
469
|
-
fs.writeFileSync(path.join(junk, "real-file.md"), "user data");
|
|
470
|
-
|
|
471
|
-
const res = await run({ yes: true });
|
|
472
|
-
|
|
473
|
-
expect(res.plan.localRemovals).toEqual([]);
|
|
474
|
-
expect(res.plan.localManualReview).toEqual([
|
|
475
|
-
{ path: junk, reason: "contains real (non-symlink) files — never auto-deleted" },
|
|
476
|
-
]);
|
|
477
|
-
expect(res.dirsRemoved).toBe(0);
|
|
478
|
-
expect(fs.existsSync(path.join(junk, "real-file.md"))).toBe(true);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
it("apply-time recheck: a regular file that replaced a planned entry between plan and apply is never removed", async () => {
|
|
482
|
-
// The plan/apply race the recheck exists for: planning classifies a junk
|
|
483
|
-
// SYMLINK entry as removable; before the apply loop reaches it, a sync
|
|
484
|
-
// pass or user edit replaces it with a REGULAR FILE. printPlan() runs
|
|
485
|
-
// between the two phases, so the first plan-print callback is the exact
|
|
486
|
-
// race window — swap the entry there.
|
|
487
|
-
fs.mkdirSync(path.join(skillsDir, "eng%3Arace"));
|
|
488
|
-
const junk = path.join(skillsDir, "eng%253Arace");
|
|
489
|
-
fs.symlinkSync(path.join(skillsDir, "eng%3Arace"), junk);
|
|
490
|
-
|
|
491
|
-
let swapped = false;
|
|
492
|
-
vi.spyOn(console, "log").mockImplementation(() => {
|
|
493
|
-
if (swapped) return;
|
|
494
|
-
swapped = true;
|
|
495
|
-
try {
|
|
496
|
-
fs.unlinkSync(junk);
|
|
497
|
-
} catch {
|
|
498
|
-
fs.rmdirSync(junk); // win32 directory symlink
|
|
499
|
-
}
|
|
500
|
-
fs.writeFileSync(junk, "user data written mid-run");
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
const res = await run({ yes: true });
|
|
504
|
-
|
|
505
|
-
expect(swapped).toBe(true);
|
|
506
|
-
expect(res.plan.localRemovals).toEqual([junk]);
|
|
507
|
-
expect(res.dirsRemoved).toBe(0);
|
|
508
|
-
expect(fs.readFileSync(junk, "utf-8")).toBe("user data written mid-run");
|
|
509
|
-
expect(res.warnings).toBeGreaterThanOrEqual(1);
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
it("refuses a junk-named entry when its canonical wrapper is missing on disk (it may be the only copy)", async () => {
|
|
513
|
-
const junk = makeSymlinkFarmDir("eng%253Aorphan");
|
|
514
|
-
|
|
515
|
-
const res = await run({ yes: true });
|
|
516
|
-
|
|
517
|
-
expect(res.plan.localRemovals).toEqual([]);
|
|
518
|
-
expect(res.plan.localManualReview).toEqual([
|
|
519
|
-
{
|
|
520
|
-
path: junk,
|
|
521
|
-
reason:
|
|
522
|
-
"canonical wrapper 'eng%3Aorphan' missing on disk — junk-named entry may be the only copy",
|
|
523
|
-
},
|
|
524
|
-
]);
|
|
525
|
-
expect(fs.existsSync(junk)).toBe(true);
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
it("removes a junk-named entry that is itself a symlink (farm content by definition)", async () => {
|
|
529
|
-
const target = path.join(tmpRoot, "wrapper-target.md");
|
|
530
|
-
fs.writeFileSync(target, "t");
|
|
531
|
-
fs.mkdirSync(path.join(skillsDir, "eng%3Alink"));
|
|
532
|
-
const junkLink = path.join(skillsDir, "eng%253Alink");
|
|
533
|
-
fs.symlinkSync(target, junkLink);
|
|
534
|
-
|
|
535
|
-
const res = await run({ yes: true });
|
|
536
|
-
|
|
537
|
-
expect(res.plan.localRemovals).toEqual([junkLink]);
|
|
538
|
-
expect(res.dirsRemoved).toBe(1);
|
|
539
|
-
expect(fs.existsSync(junkLink)).toBe(false);
|
|
540
|
-
// Symlink removal never follows through to the target.
|
|
541
|
-
expect(fs.existsSync(target)).toBe(true);
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
it("never GCs a colon-free percent-named wrapper, even when its double-encoded twin exists on disk", async () => {
|
|
545
|
-
// Codex P2 (round-9 follow-up): `canonicalVaultSegmentSpelling` returns
|
|
546
|
-
// colon-free names UNCHANGED on purpose — `foo%25bar` is the legitimate
|
|
547
|
-
// win32 wrapper for the canonical skill name `foo%bar`, not a generation
|
|
548
|
-
// of a `<ns>:<skill>` amplifier family. Pre-fix, the local GC re-encoded
|
|
549
|
-
// that already-canonical name for the host (`foo%2525bar`); because that
|
|
550
|
-
// spelling differs from the entry's own, the entry fell through the
|
|
551
|
-
// "already canonical" guard and, with a matching double-encoded sibling
|
|
552
|
-
// on disk, `--yes` deleted the legitimate wrapper. Both spellings here
|
|
553
|
-
// are their own canonical form, so BOTH must survive untouched.
|
|
554
|
-
const legit = makeSymlinkFarmDir("foo%25bar");
|
|
555
|
-
const twin = makeSymlinkFarmDir("foo%2525bar");
|
|
556
|
-
// A genuine namespaced amplifier family in the same directory proves the
|
|
557
|
-
// guard is scoped to colon-free names and did not disable the GC.
|
|
558
|
-
fs.mkdirSync(path.join(skillsDir, "eng%3Aarchitect"));
|
|
559
|
-
const amplifierJunk = makeSymlinkFarmDir("eng%253Aarchitect");
|
|
560
|
-
|
|
561
|
-
const res = await run({ yes: true });
|
|
562
|
-
|
|
563
|
-
expect(res.plan.localRemovals).toEqual([amplifierJunk]);
|
|
564
|
-
expect(res.plan.localManualReview).toEqual([]);
|
|
565
|
-
expect(fs.existsSync(legit)).toBe(true);
|
|
566
|
-
expect(fs.existsSync(twin)).toBe(true);
|
|
567
|
-
expect(fs.existsSync(amplifierJunk)).toBe(false);
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
it("leaves canonical wrapper names and ordinary skill dirs alone", async () => {
|
|
571
|
-
fs.mkdirSync(path.join(skillsDir, "eng%3Aarchitect")); // canonical win32 wrapper
|
|
572
|
-
fs.mkdirSync(path.join(skillsDir, "plain-skill")); // no encoding at all
|
|
573
|
-
|
|
574
|
-
const res = await run({ yes: true });
|
|
575
|
-
|
|
576
|
-
expect(res.plan.localRemovals).toEqual([]);
|
|
577
|
-
expect(res.plan.localManualReview).toEqual([]);
|
|
578
|
-
expect(fs.existsSync(path.join(skillsDir, "eng%3Aarchitect"))).toBe(true);
|
|
579
|
-
expect(fs.existsSync(path.join(skillsDir, "plain-skill"))).toBe(true);
|
|
580
|
-
});
|
|
581
|
-
});
|