@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,124 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { promises as fs } from "node:fs";
|
|
3
|
-
import * as os from "node:os";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
|
|
8
|
-
type ChildResult = {
|
|
9
|
-
code: number | null;
|
|
10
|
-
signal: NodeJS.Signals | null;
|
|
11
|
-
stdout: string;
|
|
12
|
-
stderr: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function runNode(scriptPath: string, env: NodeJS.ProcessEnv): Promise<ChildResult> {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const child = spawn(process.execPath, [scriptPath], {
|
|
18
|
-
env,
|
|
19
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
20
|
-
});
|
|
21
|
-
let stdout = "";
|
|
22
|
-
let stderr = "";
|
|
23
|
-
child.stdout.setEncoding("utf-8");
|
|
24
|
-
child.stderr.setEncoding("utf-8");
|
|
25
|
-
child.stdout.on("data", (chunk: string) => {
|
|
26
|
-
stdout += chunk;
|
|
27
|
-
});
|
|
28
|
-
child.stderr.on("data", (chunk: string) => {
|
|
29
|
-
stderr += chunk;
|
|
30
|
-
});
|
|
31
|
-
child.once("error", reject);
|
|
32
|
-
child.once("close", (code, signal) => {
|
|
33
|
-
resolve({ code, signal, stdout, stderr });
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe("built sync runner — oversized skill transcript", () => {
|
|
39
|
-
it("drains a multi-budget transcript in a child process without a fatal abort", async () => {
|
|
40
|
-
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "hqcloud-skill-e2e-"));
|
|
41
|
-
try {
|
|
42
|
-
const home = path.join(tmp, "home");
|
|
43
|
-
const hqRoot = path.join(home, "hq");
|
|
44
|
-
const sessionDir = path.join(home, ".claude", "projects", "-hq");
|
|
45
|
-
await fs.mkdir(sessionDir, { recursive: true });
|
|
46
|
-
await fs.mkdir(hqRoot, { recursive: true });
|
|
47
|
-
|
|
48
|
-
// Five 1.5 MiB JSONL records exceed the runner's default 4 MiB source
|
|
49
|
-
// budget. The normal runner entrypoint must therefore advance over three
|
|
50
|
-
// bounded passes instead of allocating/decoding the whole transcript.
|
|
51
|
-
const filler = "x".repeat(1_500_000);
|
|
52
|
-
const expectedSkills = Array.from({ length: 5 }, (_, i) => `deploy-${i}`);
|
|
53
|
-
const transcript = expectedSkills
|
|
54
|
-
.map((skill, i) =>
|
|
55
|
-
JSON.stringify({
|
|
56
|
-
type: "user",
|
|
57
|
-
sessionId: "oversized-session",
|
|
58
|
-
timestamp: `2026-08-02T12:0${i}:00.000Z`,
|
|
59
|
-
cwd: hqRoot,
|
|
60
|
-
uuid: `oversized-${i}`,
|
|
61
|
-
message: {
|
|
62
|
-
role: "user",
|
|
63
|
-
content: `<command-name>/${skill}</command-name><command-args>${filler}</command-args>`,
|
|
64
|
-
},
|
|
65
|
-
}),
|
|
66
|
-
)
|
|
67
|
-
.join("\n") + "\n";
|
|
68
|
-
const transcriptPath = path.join(sessionDir, "oversized.jsonl");
|
|
69
|
-
await fs.writeFile(transcriptPath, transcript, "utf-8");
|
|
70
|
-
|
|
71
|
-
const runnerUrl = pathToFileURL(
|
|
72
|
-
path.join(process.cwd(), "dist", "bin", "sync-runner.js"),
|
|
73
|
-
).href;
|
|
74
|
-
const wrapperPath = path.join(tmp, "run-built-telemetry.mjs");
|
|
75
|
-
await fs.writeFile(
|
|
76
|
-
wrapperPath,
|
|
77
|
-
`import { promises as fs } from "node:fs";
|
|
78
|
-
import path from "node:path";
|
|
79
|
-
import { defaultCollectTelemetry } from ${JSON.stringify(runnerUrl)};
|
|
80
|
-
const hqRoot = process.env.TEST_HQ_ROOT;
|
|
81
|
-
const cursorPath = path.join(process.env.HOME, ".hq", "skill-telemetry-cursor.json");
|
|
82
|
-
const postedSkills = [];
|
|
83
|
-
const client = {
|
|
84
|
-
entity: { listByType: async () => [{ uid: "prs_skill_telemetry_e2e", type: "person", slug: "skill-telemetry-e2e", status: "active", bucketName: "hq-vault-prs_skill_telemetry_e2e", createdAt: "2026-08-02T00:00:00Z" }] },
|
|
85
|
-
getTelemetryOptIn: async () => ({ enabled: true, updatedAt: null }),
|
|
86
|
-
postUsage: async () => ({ ok: true, written: 0, skipped: [] }),
|
|
87
|
-
postSkillInvocations: async (batch) => { postedSkills.push(...batch.events.map((event) => event.skill)); return { ok: true, written: batch.events.length, skipped: [] }; },
|
|
88
|
-
postOutcomeEvents: async () => ({ ok: true, written: 0, skipped: [] }),
|
|
89
|
-
};
|
|
90
|
-
const offsets = [];
|
|
91
|
-
for (let pass = 0; pass < 3; pass += 1) {
|
|
92
|
-
await defaultCollectTelemetry(client, false, hqRoot);
|
|
93
|
-
const cursor = JSON.parse(await fs.readFile(cursorPath, "utf-8"));
|
|
94
|
-
offsets.push(cursor.files[process.env.TEST_TRANSCRIPT_PATH]?.offset ?? 0);
|
|
95
|
-
}
|
|
96
|
-
process.stdout.write(JSON.stringify({ offsets, postedSkills }));\n`,
|
|
97
|
-
"utf-8",
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const result = await runNode(wrapperPath, {
|
|
101
|
-
...process.env,
|
|
102
|
-
HOME: home,
|
|
103
|
-
TEST_HQ_ROOT: hqRoot,
|
|
104
|
-
TEST_TRANSCRIPT_PATH: transcriptPath,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(result.signal).toBeNull();
|
|
108
|
-
expect(result.code).toBe(0);
|
|
109
|
-
expect(result.stderr).not.toContain("Fatal error");
|
|
110
|
-
expect(result.stderr).not.toContain("Check failed: i::kMaxInt >= len");
|
|
111
|
-
const output = JSON.parse(result.stdout) as {
|
|
112
|
-
offsets: number[];
|
|
113
|
-
postedSkills: string[];
|
|
114
|
-
};
|
|
115
|
-
expect(output.offsets[0]).toBeGreaterThan(0);
|
|
116
|
-
expect(output.offsets[0]).toBeLessThan(output.offsets[1]);
|
|
117
|
-
expect(output.offsets[1]).toBeLessThan(output.offsets[2]);
|
|
118
|
-
expect(output.offsets[2]).toBe(Buffer.byteLength(transcript, "utf-8"));
|
|
119
|
-
expect(output.postedSkills).toEqual(expectedSkills);
|
|
120
|
-
} finally {
|
|
121
|
-
await fs.rm(tmp, { recursive: true, force: true });
|
|
122
|
-
}
|
|
123
|
-
}, 30_000);
|
|
124
|
-
});
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Artifact-level regression for HQ-SYNC-X.
|
|
3
|
-
*
|
|
4
|
-
* This starts the compiled runner as a child process. The local vault stub
|
|
5
|
-
* completes authentication, membership discovery, entity lookup, and the
|
|
6
|
-
* normal company-vault list. Only the personal vault's direct-S3 endpoint uses
|
|
7
|
-
* an unresolvable `.invalid` host. That makes the real sync function reject
|
|
8
|
-
* from its fanout leg, rather than synthesizing a per-file error or failing at
|
|
9
|
-
* the initial GET /membership/me boundary (which already returns 75).
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { createServer, type Server } from "node:http";
|
|
13
|
-
import { once } from "node:events";
|
|
14
|
-
import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
15
|
-
import { tmpdir } from "node:os";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import { fileURLToPath } from "node:url";
|
|
18
|
-
import { spawn } from "node:child_process";
|
|
19
|
-
|
|
20
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
21
|
-
|
|
22
|
-
const repoRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
|
23
|
-
const artifactPath = process.env.HQ_CLOUD_E2E_ARTIFACT
|
|
24
|
-
? path.resolve(process.env.HQ_CLOUD_E2E_ARTIFACT)
|
|
25
|
-
: path.join(repoRoot, "dist", "bin", "sync-runner.js");
|
|
26
|
-
|
|
27
|
-
const companyUid = "cmp_clean_e2e";
|
|
28
|
-
const companySlug = "clean-e2e";
|
|
29
|
-
const personalUid = "prs_transient_e2e";
|
|
30
|
-
const invalidS3Endpoint = "http://hq-vault-transient-company-leg.invalid";
|
|
31
|
-
|
|
32
|
-
let fixtureRoot: string | undefined;
|
|
33
|
-
let hqRoot: string;
|
|
34
|
-
let testHome: string;
|
|
35
|
-
let server: Server | undefined;
|
|
36
|
-
let vaultUrl: string;
|
|
37
|
-
let stsCredentialExpiration: string;
|
|
38
|
-
const requests: string[] = [];
|
|
39
|
-
let personListReads = 0;
|
|
40
|
-
|
|
41
|
-
function json(response: import("node:http").ServerResponse, body: unknown): void {
|
|
42
|
-
response.writeHead(200, { "content-type": "application/json" });
|
|
43
|
-
response.end(JSON.stringify(body));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function ensureArtifact(): Promise<void> {
|
|
47
|
-
try {
|
|
48
|
-
await access(artifactPath);
|
|
49
|
-
return;
|
|
50
|
-
} catch (err) {
|
|
51
|
-
// An explicit artifact path is used only by the base-commit proof. Do not
|
|
52
|
-
// hide a bad path there by building the candidate artifact instead.
|
|
53
|
-
if (process.env.HQ_CLOUD_E2E_ARTIFACT) throw err;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
await new Promise<void>((resolve, reject) => {
|
|
57
|
-
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
58
|
-
const child = spawn(npm, ["run", "build"], {
|
|
59
|
-
cwd: repoRoot,
|
|
60
|
-
stdio: "inherit",
|
|
61
|
-
});
|
|
62
|
-
child.once("error", reject);
|
|
63
|
-
child.once("close", (code) => {
|
|
64
|
-
if (code === 0) resolve();
|
|
65
|
-
else reject(new Error(`npm run build exited ${code ?? "without a status"}`));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
await access(artifactPath);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function runArtifact(): Promise<{
|
|
72
|
-
code: number | null;
|
|
73
|
-
stdout: string;
|
|
74
|
-
stderr: string;
|
|
75
|
-
}> {
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const child = spawn(
|
|
78
|
-
process.execPath,
|
|
79
|
-
[artifactPath, "--companies", "--hq-root", hqRoot, "--json"],
|
|
80
|
-
{
|
|
81
|
-
cwd: path.dirname(artifactPath),
|
|
82
|
-
env: {
|
|
83
|
-
...process.env,
|
|
84
|
-
HOME: testHome,
|
|
85
|
-
HQ_MACHINE_ID: "e2e-transient-company-leg",
|
|
86
|
-
HQ_QMD_REINDEX_ON_SYNC: "0",
|
|
87
|
-
HQ_STATE_DIR: path.join(testHome, ".hq"),
|
|
88
|
-
HQ_VAULT_API_URL: vaultUrl,
|
|
89
|
-
AWS_ENDPOINT_URL: invalidS3Endpoint,
|
|
90
|
-
},
|
|
91
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
let stdout = "";
|
|
95
|
-
let stderr = "";
|
|
96
|
-
child.stdout.on("data", (chunk: Buffer) => {
|
|
97
|
-
stdout += chunk.toString();
|
|
98
|
-
});
|
|
99
|
-
child.stderr.on("data", (chunk: Buffer) => {
|
|
100
|
-
stderr += chunk.toString();
|
|
101
|
-
});
|
|
102
|
-
const timeout = setTimeout(() => {
|
|
103
|
-
child.kill("SIGTERM");
|
|
104
|
-
reject(new Error("compiled sync runner did not exit within 15 seconds"));
|
|
105
|
-
}, 15_000);
|
|
106
|
-
child.once("error", (err) => {
|
|
107
|
-
clearTimeout(timeout);
|
|
108
|
-
reject(err);
|
|
109
|
-
});
|
|
110
|
-
child.once("close", (code) => {
|
|
111
|
-
clearTimeout(timeout);
|
|
112
|
-
resolve({ code, stdout, stderr });
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function runWatchArtifact(): Promise<{
|
|
118
|
-
code: number | null;
|
|
119
|
-
signal: NodeJS.Signals | null;
|
|
120
|
-
stdout: string;
|
|
121
|
-
stderr: string;
|
|
122
|
-
}> {
|
|
123
|
-
return new Promise((resolve, reject) => {
|
|
124
|
-
const child = spawn(
|
|
125
|
-
process.execPath,
|
|
126
|
-
[
|
|
127
|
-
artifactPath,
|
|
128
|
-
"--companies",
|
|
129
|
-
"--hq-root",
|
|
130
|
-
hqRoot,
|
|
131
|
-
"--json",
|
|
132
|
-
"--watch",
|
|
133
|
-
"--poll-remote-ms",
|
|
134
|
-
"25",
|
|
135
|
-
],
|
|
136
|
-
{
|
|
137
|
-
cwd: path.dirname(artifactPath),
|
|
138
|
-
env: {
|
|
139
|
-
...process.env,
|
|
140
|
-
HOME: testHome,
|
|
141
|
-
HQ_MACHINE_ID: "e2e-transient-company-leg",
|
|
142
|
-
HQ_QMD_REINDEX_ON_SYNC: "0",
|
|
143
|
-
HQ_STATE_DIR: path.join(testHome, ".hq"),
|
|
144
|
-
HQ_VAULT_API_URL: vaultUrl,
|
|
145
|
-
AWS_ENDPOINT_URL: invalidS3Endpoint,
|
|
146
|
-
},
|
|
147
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
148
|
-
},
|
|
149
|
-
);
|
|
150
|
-
let stdout = "";
|
|
151
|
-
let stderr = "";
|
|
152
|
-
let stopping = false;
|
|
153
|
-
const stop = () => {
|
|
154
|
-
if (stopping || child.exitCode !== null) return;
|
|
155
|
-
stopping = true;
|
|
156
|
-
child.kill("SIGTERM");
|
|
157
|
-
};
|
|
158
|
-
const timeout = setTimeout(() => {
|
|
159
|
-
stop();
|
|
160
|
-
reject(new Error("watching compiled sync runner did not complete two polls within 20 seconds"));
|
|
161
|
-
}, 20_000);
|
|
162
|
-
child.stdout.on("data", (chunk: Buffer) => {
|
|
163
|
-
stdout += chunk.toString();
|
|
164
|
-
const completePasses = (stdout.match(/"type":"all-complete"/g) ?? []).length;
|
|
165
|
-
if (completePasses >= 2) stop();
|
|
166
|
-
});
|
|
167
|
-
child.stderr.on("data", (chunk: Buffer) => {
|
|
168
|
-
stderr += chunk.toString();
|
|
169
|
-
});
|
|
170
|
-
child.once("error", (err) => {
|
|
171
|
-
clearTimeout(timeout);
|
|
172
|
-
reject(err);
|
|
173
|
-
});
|
|
174
|
-
child.once("close", (code, signal) => {
|
|
175
|
-
clearTimeout(timeout);
|
|
176
|
-
resolve({ code, signal, stdout, stderr });
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
beforeEach(async () => {
|
|
182
|
-
await ensureArtifact();
|
|
183
|
-
const expiry = new Date();
|
|
184
|
-
expiry.setUTCFullYear(expiry.getUTCFullYear() + 100);
|
|
185
|
-
stsCredentialExpiration = expiry.toISOString();
|
|
186
|
-
fixtureRoot = await mkdtemp(path.join(tmpdir(), "hqcloud-transient-company-leg-e2e-"));
|
|
187
|
-
hqRoot = path.join(fixtureRoot, "hq");
|
|
188
|
-
testHome = path.join(fixtureRoot, "home");
|
|
189
|
-
await mkdir(path.join(hqRoot, "companies", companySlug), { recursive: true });
|
|
190
|
-
await mkdir(path.join(testHome, ".hq"), { recursive: true });
|
|
191
|
-
const fakeJwtPayload = Buffer.from(
|
|
192
|
-
JSON.stringify({ sub: "e2e-subject", exp: Math.floor(Date.now() / 1000) + 3600 }),
|
|
193
|
-
).toString("base64url");
|
|
194
|
-
await writeFile(
|
|
195
|
-
path.join(testHome, ".hq", "cognito-tokens.json"),
|
|
196
|
-
JSON.stringify({
|
|
197
|
-
accessToken: `header.${fakeJwtPayload}.signature`,
|
|
198
|
-
idToken: `header.${fakeJwtPayload}.signature`,
|
|
199
|
-
refreshToken: "e2e-only",
|
|
200
|
-
expiresAt: Date.now() + 60 * 60 * 1000,
|
|
201
|
-
tokenType: "Bearer",
|
|
202
|
-
}),
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
requests.length = 0;
|
|
206
|
-
personListReads = 0;
|
|
207
|
-
server = createServer((request, response) => {
|
|
208
|
-
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
209
|
-
requests.push(`${request.method} ${url.pathname}`);
|
|
210
|
-
if (request.method === "GET" && url.pathname === "/membership/me") {
|
|
211
|
-
json(response, { memberships: [{ companyUid }] });
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (request.method === "GET" && url.pathname === `/entity/${companyUid}`) {
|
|
215
|
-
json(response, {
|
|
216
|
-
entity: {
|
|
217
|
-
uid: companyUid,
|
|
218
|
-
slug: companySlug,
|
|
219
|
-
type: "company",
|
|
220
|
-
bucketName: "hq-vault-e2e",
|
|
221
|
-
status: "active",
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (request.method === "GET" && url.pathname === `/entity/${personalUid}`) {
|
|
227
|
-
json(response, {
|
|
228
|
-
entity: {
|
|
229
|
-
uid: personalUid,
|
|
230
|
-
slug: "personal-e2e",
|
|
231
|
-
type: "person",
|
|
232
|
-
bucketName: "hq-vault-e2e-personal",
|
|
233
|
-
status: "active",
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (request.method === "GET" && url.pathname === "/v1/files/list") {
|
|
239
|
-
json(response, {
|
|
240
|
-
objects: [],
|
|
241
|
-
cursor: null,
|
|
242
|
-
truncated: false,
|
|
243
|
-
});
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (request.method === "POST" && url.pathname === "/sts/vend-self") {
|
|
247
|
-
json(response, {
|
|
248
|
-
credentials: {
|
|
249
|
-
accessKeyId: "e2e-access-key",
|
|
250
|
-
secretAccessKey: "e2e-secret-key",
|
|
251
|
-
sessionToken: "e2e-session-token",
|
|
252
|
-
expiration: stsCredentialExpiration,
|
|
253
|
-
},
|
|
254
|
-
expiresAt: stsCredentialExpiration,
|
|
255
|
-
});
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
if (request.method === "GET" && url.pathname === "/entity/by-type/person") {
|
|
259
|
-
personListReads += 1;
|
|
260
|
-
json(response, {
|
|
261
|
-
entities:
|
|
262
|
-
personListReads % 2 === 1
|
|
263
|
-
? [
|
|
264
|
-
{
|
|
265
|
-
uid: personalUid,
|
|
266
|
-
slug: "personal-e2e",
|
|
267
|
-
type: "person",
|
|
268
|
-
bucketName: "hq-vault-e2e-personal",
|
|
269
|
-
status: "active",
|
|
270
|
-
},
|
|
271
|
-
]
|
|
272
|
-
: [],
|
|
273
|
-
});
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
if (request.method === "GET" && url.pathname === "/membership/pending-by-email") {
|
|
277
|
-
json(response, { invites: [] });
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
if (request.method === "POST") {
|
|
281
|
-
json(response, { ok: true, written: 0, skipped: [] });
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
response.writeHead(404, { "content-type": "application/json" });
|
|
285
|
-
response.end(JSON.stringify({ error: `unexpected ${request.method} ${url.pathname}` }));
|
|
286
|
-
});
|
|
287
|
-
server.listen(0, "127.0.0.1");
|
|
288
|
-
await once(server, "listening");
|
|
289
|
-
const address = server.address();
|
|
290
|
-
if (!address || typeof address === "string") {
|
|
291
|
-
throw new Error("e2e vault stub did not bind a TCP port");
|
|
292
|
-
}
|
|
293
|
-
vaultUrl = `http://127.0.0.1:${address.port}`;
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
afterEach(async () => {
|
|
297
|
-
if (server?.listening) {
|
|
298
|
-
server.close();
|
|
299
|
-
await once(server, "close");
|
|
300
|
-
}
|
|
301
|
-
if (fixtureRoot) {
|
|
302
|
-
await rm(fixtureRoot, { recursive: true, force: true });
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe("compiled sync runner transient company leg (HQ-SYNC-X)", () => {
|
|
307
|
-
it(
|
|
308
|
-
"returns 75 and emits transient-network when only the personal vault S3 leg cannot resolve",
|
|
309
|
-
async () => {
|
|
310
|
-
const result = await runArtifact();
|
|
311
|
-
|
|
312
|
-
expect(
|
|
313
|
-
result.code,
|
|
314
|
-
`stdout=${result.stdout}\nstderr=${result.stderr}`,
|
|
315
|
-
).toBe(75);
|
|
316
|
-
expect(requests).toEqual(
|
|
317
|
-
expect.arrayContaining([
|
|
318
|
-
"GET /membership/me",
|
|
319
|
-
`GET /entity/${companyUid}`,
|
|
320
|
-
"GET /v1/files/list",
|
|
321
|
-
"POST /sts/vend-self",
|
|
322
|
-
]),
|
|
323
|
-
);
|
|
324
|
-
const stdoutEvents = result.stdout
|
|
325
|
-
.trim()
|
|
326
|
-
.split("\n")
|
|
327
|
-
.filter(Boolean)
|
|
328
|
-
.map((line) => JSON.parse(line) as Record<string, unknown>);
|
|
329
|
-
expect(
|
|
330
|
-
stdoutEvents.filter((event) => event.type === "transient-network"),
|
|
331
|
-
).toEqual([
|
|
332
|
-
expect.objectContaining({
|
|
333
|
-
company: "personal",
|
|
334
|
-
path: "(company)",
|
|
335
|
-
message: expect.stringContaining("ENOTFOUND"),
|
|
336
|
-
}),
|
|
337
|
-
]);
|
|
338
|
-
expect(
|
|
339
|
-
stdoutEvents.some(
|
|
340
|
-
(event) => event.type === "error" && event.path === "(company)",
|
|
341
|
-
),
|
|
342
|
-
).toBe(false);
|
|
343
|
-
expect(stdoutEvents.find((event) => event.type === "all-complete")).toEqual(
|
|
344
|
-
expect.objectContaining({
|
|
345
|
-
errors: [],
|
|
346
|
-
transient: [expect.objectContaining({ company: "personal" })],
|
|
347
|
-
}),
|
|
348
|
-
);
|
|
349
|
-
expect(result.stderr).not.toContain('"path":"(company)"');
|
|
350
|
-
},
|
|
351
|
-
30_000,
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
it(
|
|
355
|
-
"stays alive through two transient company-leg passes until SIGTERM stops it",
|
|
356
|
-
async () => {
|
|
357
|
-
const result = await runWatchArtifact();
|
|
358
|
-
expect(
|
|
359
|
-
{ code: result.code, signal: result.signal },
|
|
360
|
-
`stdout=${result.stdout}\nstderr=${result.stderr}`,
|
|
361
|
-
).toEqual({ code: null, signal: "SIGTERM" });
|
|
362
|
-
|
|
363
|
-
const stdoutEvents = result.stdout
|
|
364
|
-
.trim()
|
|
365
|
-
.split("\n")
|
|
366
|
-
.filter(Boolean)
|
|
367
|
-
.map((line) => JSON.parse(line) as Record<string, unknown>);
|
|
368
|
-
expect(
|
|
369
|
-
stdoutEvents.filter((event) => event.type === "all-complete"),
|
|
370
|
-
).toHaveLength(2);
|
|
371
|
-
expect(
|
|
372
|
-
stdoutEvents.filter(
|
|
373
|
-
(event) =>
|
|
374
|
-
event.type === "transient-network" && event.company === "personal",
|
|
375
|
-
),
|
|
376
|
-
).toHaveLength(2);
|
|
377
|
-
expect(result.stderr).toContain(
|
|
378
|
-
"watch pass skipped — transient network failure; retrying next poll",
|
|
379
|
-
);
|
|
380
|
-
expect(result.stderr).not.toContain('"path":"(company)"');
|
|
381
|
-
},
|
|
382
|
-
30_000,
|
|
383
|
-
);
|
|
384
|
-
});
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Artifact-level regression for the Windows EINVAL reparse-point failure.
|
|
3
|
-
*
|
|
4
|
-
* The Linux test runner cannot create the production reparse-point shape, so
|
|
5
|
-
* the fs seam makes a real symlink's readlink raise EINVAL while the actual
|
|
6
|
-
* runner → company fanout → share walk executes over a temp HQ tree.
|
|
7
|
-
*/
|
|
8
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import {
|
|
12
|
-
runRunner,
|
|
13
|
-
type RunnerDeps,
|
|
14
|
-
type RunnerEvent,
|
|
15
|
-
type VaultClientSurface,
|
|
16
|
-
} from "../../../src/bin/sync-runner.js";
|
|
17
|
-
import { share } from "../../../src/cli/share.js";
|
|
18
|
-
import type { EntityContext, EntityInfo } from "../../../src/types.js";
|
|
19
|
-
import { uploadFile, uploadSymlink } from "../../../src/s3.js";
|
|
20
|
-
|
|
21
|
-
vi.mock("fs", async (importOriginal) => {
|
|
22
|
-
const actual = await importOriginal<typeof import("fs")>();
|
|
23
|
-
return { ...actual };
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
vi.mock("../../../src/s3.js", async (importOriginal) => {
|
|
27
|
-
const actual = await importOriginal<typeof import("../../../src/s3.js")>();
|
|
28
|
-
return {
|
|
29
|
-
...actual,
|
|
30
|
-
uploadFile: vi.fn().mockResolvedValue({ etag: '"upload-etag"' }),
|
|
31
|
-
uploadSymlink: vi.fn().mockResolvedValue({ etag: '"symlink-etag"' }),
|
|
32
|
-
headRemoteFile: vi.fn().mockResolvedValue(null),
|
|
33
|
-
primeObjectTransport: vi.fn().mockResolvedValue(undefined),
|
|
34
|
-
primeUploads: vi.fn().mockResolvedValue(undefined),
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
function errnoError(code: string): NodeJS.ErrnoException {
|
|
39
|
-
const err = new Error(`${code}: invalid argument, readlink`) as NodeJS.ErrnoException;
|
|
40
|
-
err.code = code;
|
|
41
|
-
return err;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function makeWriter(): {
|
|
45
|
-
write: (chunk: string) => boolean;
|
|
46
|
-
events: () => RunnerEvent[];
|
|
47
|
-
} {
|
|
48
|
-
let output = "";
|
|
49
|
-
return {
|
|
50
|
-
write: (chunk) => {
|
|
51
|
-
output += chunk;
|
|
52
|
-
return true;
|
|
53
|
-
},
|
|
54
|
-
events: () =>
|
|
55
|
-
output
|
|
56
|
-
.split("\n")
|
|
57
|
-
.filter(Boolean)
|
|
58
|
-
.map((line) => JSON.parse(line) as RunnerEvent),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let hqRoot: string;
|
|
63
|
-
let stateDir: string;
|
|
64
|
-
let unreadableLink: string;
|
|
65
|
-
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
// Keep fixture roots inside the checkout so operator runs never create a
|
|
68
|
-
// scratch HQ tree outside the task worktree.
|
|
69
|
-
hqRoot = fs.mkdtempSync(path.join(process.cwd(), ".hqcloud-einval-e2e-"));
|
|
70
|
-
stateDir = fs.mkdtempSync(path.join(process.cwd(), ".hqcloud-einval-state-"));
|
|
71
|
-
process.env.HQ_STATE_DIR = stateDir;
|
|
72
|
-
const companyRoot = path.join(hqRoot, "companies", "acme");
|
|
73
|
-
const policiesDir = path.join(companyRoot, "policies");
|
|
74
|
-
const targetDir = path.join(hqRoot, "outside", "target");
|
|
75
|
-
fs.mkdirSync(policiesDir, { recursive: true });
|
|
76
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
77
|
-
fs.writeFileSync(path.join(policiesDir, "safe.md"), "safe bytes");
|
|
78
|
-
fs.writeFileSync(path.join(targetDir, "must-not-upload.md"), "target bytes");
|
|
79
|
-
unreadableLink = path.join(policiesDir, "unreadable-link");
|
|
80
|
-
fs.symlinkSync(targetDir, unreadableLink, "dir");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
afterEach(() => {
|
|
84
|
-
vi.restoreAllMocks();
|
|
85
|
-
fs.rmSync(hqRoot, { recursive: true, force: true });
|
|
86
|
-
fs.rmSync(stateDir, { recursive: true, force: true });
|
|
87
|
-
delete process.env.HQ_STATE_DIR;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe("sync runner unreadable Windows link", () => {
|
|
91
|
-
it("keeps the leg complete and emits the offending relative path", async () => {
|
|
92
|
-
const stdout = makeWriter();
|
|
93
|
-
const stderr = makeWriter();
|
|
94
|
-
const entityContext: EntityContext = {
|
|
95
|
-
uid: "cmp_acme",
|
|
96
|
-
slug: "acme",
|
|
97
|
-
bucketName: "hq-vault-acme-test",
|
|
98
|
-
region: "us-east-1",
|
|
99
|
-
credentials: {
|
|
100
|
-
accessKeyId: "test-key",
|
|
101
|
-
secretAccessKey: "test-secret",
|
|
102
|
-
sessionToken: "test-session",
|
|
103
|
-
},
|
|
104
|
-
expiresAt: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
|
|
105
|
-
};
|
|
106
|
-
const client = {
|
|
107
|
-
listMyMemberships: async () => [{ companyUid: "cmp_acme" }],
|
|
108
|
-
listMyPendingInvitesByEmail: async () => [],
|
|
109
|
-
claimPendingInvitesByEmail: async () => undefined,
|
|
110
|
-
ensureMyPersonEntity: async () => ({}) as EntityInfo,
|
|
111
|
-
entity: {
|
|
112
|
-
get: async (uid: string) => ({
|
|
113
|
-
uid,
|
|
114
|
-
type: "company",
|
|
115
|
-
slug: "acme",
|
|
116
|
-
bucketName: "hq-vault-acme-test",
|
|
117
|
-
status: "active",
|
|
118
|
-
}) as EntityInfo,
|
|
119
|
-
listByType: async () => [],
|
|
120
|
-
},
|
|
121
|
-
} as unknown as VaultClientSurface;
|
|
122
|
-
const realReadlinkSync = fs.readlinkSync;
|
|
123
|
-
const readlinkSpy = vi
|
|
124
|
-
.spyOn(fs, "readlinkSync")
|
|
125
|
-
.mockImplementation(((candidate: fs.PathLike) => {
|
|
126
|
-
if (candidate === unreadableLink) throw errnoError("EINVAL");
|
|
127
|
-
return realReadlinkSync(candidate);
|
|
128
|
-
}) as typeof fs.readlinkSync);
|
|
129
|
-
const deps: RunnerDeps = {
|
|
130
|
-
stdout,
|
|
131
|
-
stderr,
|
|
132
|
-
getAccessToken: async () => "test-access-token",
|
|
133
|
-
getIdTokenClaims: () => null,
|
|
134
|
-
createVaultClient: () => client,
|
|
135
|
-
share: async (options) => {
|
|
136
|
-
const { vaultConfig: _vaultConfig, ...shareOptions } = options;
|
|
137
|
-
return share({ ...shareOptions, entityContext });
|
|
138
|
-
},
|
|
139
|
-
reindex: () => ({ status: 0 }) as ReturnType<NonNullable<RunnerDeps["reindex"]>>,
|
|
140
|
-
qmdReindex: () => ({
|
|
141
|
-
qmdAvailable: true,
|
|
142
|
-
collectionsAdded: [],
|
|
143
|
-
pathDriftDetected: [],
|
|
144
|
-
collectionsRepaired: [],
|
|
145
|
-
updated: false,
|
|
146
|
-
embedded: false,
|
|
147
|
-
pendingDirty: false,
|
|
148
|
-
lockBusy: false,
|
|
149
|
-
timedOut: false,
|
|
150
|
-
corruptionQuarantined: false,
|
|
151
|
-
corruptionQuarantineFailed: false,
|
|
152
|
-
indexDir: null,
|
|
153
|
-
}) as ReturnType<NonNullable<RunnerDeps["qmdReindex"]>>,
|
|
154
|
-
reconcileManifest: async () => ({
|
|
155
|
-
written: false,
|
|
156
|
-
added: [],
|
|
157
|
-
updated: [],
|
|
158
|
-
skipped: [],
|
|
159
|
-
}) as Awaited<ReturnType<NonNullable<RunnerDeps["reconcileManifest"]>>>,
|
|
160
|
-
collectTelemetry: async () => undefined,
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
const code = await runRunner(
|
|
165
|
-
["--companies", "--direction", "push", "--hq-root", hqRoot],
|
|
166
|
-
deps,
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
expect(code).toBe(0);
|
|
170
|
-
expect(stdout.events()).toContainEqual({
|
|
171
|
-
type: "not-shipped",
|
|
172
|
-
company: "acme",
|
|
173
|
-
reason: "unreadable-link",
|
|
174
|
-
count: 1,
|
|
175
|
-
samplePaths: ["policies/unreadable-link"],
|
|
176
|
-
});
|
|
177
|
-
expect(stdout.events()).toContainEqual(
|
|
178
|
-
expect.objectContaining({
|
|
179
|
-
type: "all-complete",
|
|
180
|
-
errors: [],
|
|
181
|
-
partial: false,
|
|
182
|
-
}),
|
|
183
|
-
);
|
|
184
|
-
expect(stderr.events()).toEqual([]);
|
|
185
|
-
expect(uploadFile).toHaveBeenCalledTimes(1);
|
|
186
|
-
expect(uploadSymlink).not.toHaveBeenCalled();
|
|
187
|
-
} finally {
|
|
188
|
-
readlinkSpy.mockRestore();
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|