@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/object-io.test.ts
DELETED
|
@@ -1,1221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the ObjectIO transport seam.
|
|
3
|
-
*
|
|
4
|
-
* Focus is the PresignObjectIO path (the new transport): it talks to a
|
|
5
|
-
* VaultClient-shaped stub for URL minting and a mocked global `fetch` for the
|
|
6
|
-
* byte movement. The S3SdkObjectIO path is already covered transitively by
|
|
7
|
-
* s3.test.ts (which exercises s3.ts through the default factory), plus a couple
|
|
8
|
-
* of factory-selection tests here.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
12
|
-
import * as http from "node:http";
|
|
13
|
-
import { once } from "node:events";
|
|
14
|
-
import { spawn } from "node:child_process";
|
|
15
|
-
import {
|
|
16
|
-
PresignObjectIO,
|
|
17
|
-
S3SdkObjectIO,
|
|
18
|
-
setObjectIOFactory,
|
|
19
|
-
setPresignedGetTransportForTesting,
|
|
20
|
-
resolveObjectIO,
|
|
21
|
-
presignObjectIOFactory,
|
|
22
|
-
type PresignedGetTransport,
|
|
23
|
-
type PresignTransportClient,
|
|
24
|
-
} from "./object-io.js";
|
|
25
|
-
import type { EntityContext } from "./types.js";
|
|
26
|
-
import type { PresignResultRow, VaultListedObject } from "./vault-client.js";
|
|
27
|
-
import { isAccessDenied } from "./sync-core.js";
|
|
28
|
-
|
|
29
|
-
const COMPANY = "cmp_test";
|
|
30
|
-
|
|
31
|
-
function fetchBackedPresignedGetTransport(): PresignedGetTransport {
|
|
32
|
-
return {
|
|
33
|
-
async get(url, headers) {
|
|
34
|
-
const response = await fetch(url, { method: "GET", headers });
|
|
35
|
-
const body = response.body;
|
|
36
|
-
return {
|
|
37
|
-
status: response.status,
|
|
38
|
-
headers: response.headers,
|
|
39
|
-
body: body
|
|
40
|
-
? (async function* (): AsyncIterable<Uint8Array> {
|
|
41
|
-
const reader = body.getReader();
|
|
42
|
-
let exhausted = false;
|
|
43
|
-
try {
|
|
44
|
-
while (true) {
|
|
45
|
-
const { done, value } = await reader.read();
|
|
46
|
-
if (done) {
|
|
47
|
-
exhausted = true;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (value.byteLength > 0) yield value;
|
|
51
|
-
}
|
|
52
|
-
} finally {
|
|
53
|
-
if (!exhausted) {
|
|
54
|
-
try {
|
|
55
|
-
await reader.cancel();
|
|
56
|
-
} catch {
|
|
57
|
-
// The response may already have been cancelled by destroy.
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
reader.releaseLock();
|
|
61
|
-
}
|
|
62
|
-
})()
|
|
63
|
-
: undefined,
|
|
64
|
-
destroy: () => {
|
|
65
|
-
void body?.cancel().catch(() => undefined);
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
setPresignedGetTransportForTesting(fetchBackedPresignedGetTransport());
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
setPresignedGetTransportForTesting(null);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
function ctx(): EntityContext {
|
|
81
|
-
return {
|
|
82
|
-
uid: COMPANY,
|
|
83
|
-
slug: "test",
|
|
84
|
-
bucketName: "bucket-test",
|
|
85
|
-
region: "us-east-1",
|
|
86
|
-
credentials: {
|
|
87
|
-
accessKeyId: "AKIA",
|
|
88
|
-
secretAccessKey: "secret",
|
|
89
|
-
sessionToken: "token",
|
|
90
|
-
},
|
|
91
|
-
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Minimal VaultClient stub. Each method returns whatever the per-test config
|
|
97
|
-
* sets; presign records the inputs it was called with so tests can assert the
|
|
98
|
-
* op/metadata/key shape the seam sends.
|
|
99
|
-
*/
|
|
100
|
-
function makeVault() {
|
|
101
|
-
const presignCalls: Array<{
|
|
102
|
-
companyUid: string;
|
|
103
|
-
op?: string;
|
|
104
|
-
keys: unknown[];
|
|
105
|
-
}> = [];
|
|
106
|
-
let nextPresign: PresignResultRow[] = [];
|
|
107
|
-
let nextList: {
|
|
108
|
-
objects: VaultListedObject[];
|
|
109
|
-
cursor: string | null;
|
|
110
|
-
truncated: boolean;
|
|
111
|
-
} = { objects: [], cursor: null, truncated: false };
|
|
112
|
-
|
|
113
|
-
const vault: PresignTransportClient = {
|
|
114
|
-
presign: async (input) => {
|
|
115
|
-
presignCalls.push({
|
|
116
|
-
companyUid: input.companyUid,
|
|
117
|
-
op: input.op,
|
|
118
|
-
keys: input.keys,
|
|
119
|
-
});
|
|
120
|
-
return { results: nextPresign, expiresAt: "2099-01-01T00:00:00.000Z" };
|
|
121
|
-
},
|
|
122
|
-
listFiles: async () => nextList,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
vault,
|
|
127
|
-
presignCalls,
|
|
128
|
-
setPresign: (rows: PresignResultRow[]) => {
|
|
129
|
-
nextPresign = rows;
|
|
130
|
-
},
|
|
131
|
-
setList: (v: typeof nextList) => {
|
|
132
|
-
nextList = v;
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
describe("factory selection", () => {
|
|
138
|
-
afterEach(() => setObjectIOFactory(null));
|
|
139
|
-
|
|
140
|
-
it("defaults to the S3 SDK transport", () => {
|
|
141
|
-
const io = resolveObjectIO(ctx());
|
|
142
|
-
expect(io).toBeInstanceOf(S3SdkObjectIO);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("setObjectIOFactory(null) resets to the default", () => {
|
|
146
|
-
const { vault } = makeVault();
|
|
147
|
-
setObjectIOFactory(presignObjectIOFactory(vault));
|
|
148
|
-
expect(resolveObjectIO(ctx())).toBeInstanceOf(PresignObjectIO);
|
|
149
|
-
setObjectIOFactory(null);
|
|
150
|
-
expect(resolveObjectIO(ctx())).toBeInstanceOf(S3SdkObjectIO);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("presign factory derives companyUid from ctx.uid", async () => {
|
|
154
|
-
const { vault, presignCalls, setPresign } = makeVault();
|
|
155
|
-
setPresign([{ key: "k", op: "get", url: "https://x/get" }]);
|
|
156
|
-
vi.stubGlobal(
|
|
157
|
-
"fetch",
|
|
158
|
-
vi.fn(async () => new Response(Buffer.from("body"), { status: 200 })),
|
|
159
|
-
);
|
|
160
|
-
const io = presignObjectIOFactory(vault)(ctx());
|
|
161
|
-
await io.getObject("k");
|
|
162
|
-
expect(presignCalls[0].companyUid).toBe(COMPANY);
|
|
163
|
-
vi.unstubAllGlobals();
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("S3SdkObjectIO.putObject — conditional-write fence", () => {
|
|
168
|
-
it("maps ifMatch (re-quoted) and ifNoneMatch onto the PutObjectCommand", async () => {
|
|
169
|
-
const io = new S3SdkObjectIO(ctx());
|
|
170
|
-
const sent: Array<Record<string, unknown>> = [];
|
|
171
|
-
// Swap the private client for a recorder — the fence mapping is pure
|
|
172
|
-
// input-shaping, no wire needed.
|
|
173
|
-
(io as unknown as { client: { send: (c: { input: Record<string, unknown> }) => Promise<unknown> } }).client = {
|
|
174
|
-
send: async (cmd) => {
|
|
175
|
-
sent.push(cmd.input);
|
|
176
|
-
return { ETag: '"landed"' };
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
await io.putObject({ key: "a", body: Buffer.from("x"), contentType: "t", ifMatch: "abc" });
|
|
180
|
-
expect(sent[0].IfMatch).toBe('"abc"'); // stripped etags re-quoted for If-Match
|
|
181
|
-
await io.putObject({ key: "a2", body: Buffer.from("x"), contentType: "t", ifMatch: '"quoted"' });
|
|
182
|
-
expect(sent[1].IfMatch).toBe('"quoted"'); // already-quoted passes through
|
|
183
|
-
await io.putObject({ key: "b", body: Buffer.from("y"), contentType: "t", ifNoneMatch: "*" });
|
|
184
|
-
expect(sent[2].IfNoneMatch).toBe("*");
|
|
185
|
-
await io.putObject({ key: "c", body: Buffer.from("z"), contentType: "t" });
|
|
186
|
-
expect(sent[3].IfMatch).toBeUndefined(); // unfenced PUT stays unfenced
|
|
187
|
-
expect(sent[3].IfNoneMatch).toBeUndefined();
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe("PresignObjectIO.putObject", () => {
|
|
192
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
193
|
-
beforeEach(() => {
|
|
194
|
-
fetchMock = vi.fn();
|
|
195
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
196
|
-
});
|
|
197
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
198
|
-
|
|
199
|
-
it("sends op:put with metadata and replays the signed headers verbatim", async () => {
|
|
200
|
-
const { vault, presignCalls, setPresign } = makeVault();
|
|
201
|
-
setPresign([
|
|
202
|
-
{
|
|
203
|
-
key: "shared/a.md",
|
|
204
|
-
op: "put",
|
|
205
|
-
url: "https://s3/put-url",
|
|
206
|
-
headers: {
|
|
207
|
-
"content-type": "text/markdown",
|
|
208
|
-
"x-amz-server-side-encryption": "aws:kms",
|
|
209
|
-
"x-amz-meta-created-by": "me@getindigo.ai",
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
]);
|
|
213
|
-
fetchMock.mockResolvedValue(
|
|
214
|
-
new Response(null, { status: 200, headers: { etag: '"abc123"' } }),
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
218
|
-
const res = await io.putObject({
|
|
219
|
-
key: "shared/a.md",
|
|
220
|
-
body: Buffer.from("hello"),
|
|
221
|
-
contentType: "text/markdown",
|
|
222
|
-
metadata: { "created-by": "me@getindigo.ai" },
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// Presign request carried op + per-key metadata.
|
|
226
|
-
expect(presignCalls[0].op).toBe("put");
|
|
227
|
-
expect(presignCalls[0].keys[0]).toMatchObject({
|
|
228
|
-
key: "shared/a.md",
|
|
229
|
-
op: "put",
|
|
230
|
-
contentType: "text/markdown",
|
|
231
|
-
metadata: { "created-by": "me@getindigo.ai" },
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// PUT replays the exact signed headers.
|
|
235
|
-
const [url, init] = fetchMock.mock.calls[0];
|
|
236
|
-
expect(url).toBe("https://s3/put-url");
|
|
237
|
-
expect(init.method).toBe("PUT");
|
|
238
|
-
expect(init.headers).toEqual({
|
|
239
|
-
"content-type": "text/markdown",
|
|
240
|
-
"x-amz-server-side-encryption": "aws:kms",
|
|
241
|
-
"x-amz-meta-created-by": "me@getindigo.ai",
|
|
242
|
-
});
|
|
243
|
-
// ETag returned with quotes stripped.
|
|
244
|
-
expect(res.etag).toBe("abc123");
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("throws on a per-key denial (error row)", async () => {
|
|
248
|
-
const { vault, setPresign } = makeVault();
|
|
249
|
-
setPresign([
|
|
250
|
-
{ key: "secret/x", op: "put", error: "forbidden", code: "ACL_DENY" },
|
|
251
|
-
]);
|
|
252
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
253
|
-
await expect(
|
|
254
|
-
io.putObject({
|
|
255
|
-
key: "secret/x",
|
|
256
|
-
body: Buffer.from("z"),
|
|
257
|
-
contentType: "text/plain",
|
|
258
|
-
}),
|
|
259
|
-
).rejects.toThrow(/denied for secret\/x.*forbidden.*ACL_DENY/);
|
|
260
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("a write denial (FILES_PRESIGN_FORBIDDEN) throws the access-denied shape so the push skips it like a denied GET", async () => {
|
|
264
|
-
const { vault, setPresign } = makeVault();
|
|
265
|
-
// The server refuses to MINT a PUT URL for a key the caller can't write
|
|
266
|
-
// (private-by-default: members hold read-only on a shared knowledge prefix).
|
|
267
|
-
setPresign([
|
|
268
|
-
{
|
|
269
|
-
key: "knowledge/clients/acme/brief.md",
|
|
270
|
-
op: "put",
|
|
271
|
-
error: "Caller lacks write permission on 'knowledge/clients/acme/brief.md'",
|
|
272
|
-
code: "FILES_PRESIGN_FORBIDDEN",
|
|
273
|
-
},
|
|
274
|
-
]);
|
|
275
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
276
|
-
let caught: unknown;
|
|
277
|
-
await io
|
|
278
|
-
.putObject({
|
|
279
|
-
key: "knowledge/clients/acme/brief.md",
|
|
280
|
-
body: Buffer.from("z"),
|
|
281
|
-
contentType: "text/markdown",
|
|
282
|
-
})
|
|
283
|
-
.catch((e) => {
|
|
284
|
-
caught = e;
|
|
285
|
-
});
|
|
286
|
-
// Same shape a denied GET/HEAD already throws (name === "Forbidden"), so the
|
|
287
|
-
// share.ts push catch routes it through `isAccessDenied` into the silent
|
|
288
|
-
// per-path skip (scopeExcludedSet) + the "N paths skipped — outside your
|
|
289
|
-
// granted access" aggregate, instead of a fatal `type:"error"` that exits
|
|
290
|
-
// the runner non-zero and floods Sentry. This is the PUT/GET symmetry that
|
|
291
|
-
// fixes the presign-put-denied crash-loop across user machines.
|
|
292
|
-
expect((caught as Error).name).toBe("Forbidden");
|
|
293
|
-
expect(isAccessDenied(caught)).toBe(true);
|
|
294
|
-
// Denied at mint time — the byte-moving PUT is never attempted.
|
|
295
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it("US-006 AC5: a transcript-consent denial (FILES_PRESIGN_TRANSCRIPT_CONSENT_REQUIRED) is skip-with-log, not fatal", async () => {
|
|
299
|
-
const { vault, setPresign } = makeVault();
|
|
300
|
-
// The US-005 consent code ends `_REQUIRED`, not `_FORBIDDEN`, so the plain
|
|
301
|
-
// suffix test alone would MISS it and let it fall through to the fatal
|
|
302
|
-
// generic Error — the recurring partial-failure this AC5 fix prevents.
|
|
303
|
-
setPresign([
|
|
304
|
-
{
|
|
305
|
-
key: "sessions/prs_1/2026-07-11T10-00-00.json",
|
|
306
|
-
op: "get",
|
|
307
|
-
error: "transcript consent required",
|
|
308
|
-
code: "FILES_PRESIGN_TRANSCRIPT_CONSENT_REQUIRED",
|
|
309
|
-
},
|
|
310
|
-
]);
|
|
311
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
312
|
-
// Monkeypatch console.warn (vitest's console interception can shadow a spy)
|
|
313
|
-
// to assert the REAL skip log fires.
|
|
314
|
-
const warnings: string[] = [];
|
|
315
|
-
const originalWarn = console.warn;
|
|
316
|
-
console.warn = (...args: unknown[]) => {
|
|
317
|
-
warnings.push(args.map(String).join(" "));
|
|
318
|
-
};
|
|
319
|
-
let caught: unknown;
|
|
320
|
-
try {
|
|
321
|
-
await io
|
|
322
|
-
.getObject("sessions/prs_1/2026-07-11T10-00-00.json")
|
|
323
|
-
.catch((e) => {
|
|
324
|
-
caught = e;
|
|
325
|
-
});
|
|
326
|
-
} finally {
|
|
327
|
-
console.warn = originalWarn;
|
|
328
|
-
}
|
|
329
|
-
// Same shape a denied GET already throws → isAccessDenied → the per-key
|
|
330
|
-
// scope-excluded skip, NOT a fatal `type:"error"` that poisons the run.
|
|
331
|
-
expect((caught as Error).name).toBe("Forbidden");
|
|
332
|
-
expect(isAccessDenied(caught)).toBe(true);
|
|
333
|
-
// A one-line skip log fires so operators can see WHY the key was skipped.
|
|
334
|
-
expect(
|
|
335
|
-
warnings.some((w) =>
|
|
336
|
-
w.includes("FILES_PRESIGN_TRANSCRIPT_CONSENT_REQUIRED"),
|
|
337
|
-
),
|
|
338
|
-
).toBe(true);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("US-006 AC5: a sessions structural-ACL denial (FILES_PRESIGN_SESSIONS_FORBIDDEN) is skip-with-log", async () => {
|
|
342
|
-
const { vault, setPresign } = makeVault();
|
|
343
|
-
// A spoofed/foreign `sessions/{uid}/` prefix the hq-pro structural gate
|
|
344
|
-
// refuses to presign. Ends `_FORBIDDEN`, so the suffix test already covers
|
|
345
|
-
// it — this pins that coverage as a regression contract for US-006.
|
|
346
|
-
setPresign([
|
|
347
|
-
{
|
|
348
|
-
key: "sessions/prs_other/y.json",
|
|
349
|
-
op: "get",
|
|
350
|
-
error: "not your session prefix",
|
|
351
|
-
code: "FILES_PRESIGN_SESSIONS_FORBIDDEN",
|
|
352
|
-
},
|
|
353
|
-
]);
|
|
354
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
355
|
-
let caught: unknown;
|
|
356
|
-
await io.getObject("sessions/prs_other/y.json").catch((e) => {
|
|
357
|
-
caught = e;
|
|
358
|
-
});
|
|
359
|
-
expect((caught as Error).name).toBe("Forbidden");
|
|
360
|
-
expect(isAccessDenied(caught)).toBe(true);
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
it("a non-authorization presign failure stays a generic (fatal) error — not silently skipped", async () => {
|
|
364
|
-
const { vault, setPresign } = makeVault();
|
|
365
|
-
setPresign([
|
|
366
|
-
{ key: "secret/x", op: "put", error: "boom", code: "PRESIGN_INTERNAL" },
|
|
367
|
-
]);
|
|
368
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
369
|
-
let caught: unknown;
|
|
370
|
-
await io
|
|
371
|
-
.putObject({ key: "secret/x", body: Buffer.from("z"), contentType: "x" })
|
|
372
|
-
.catch((e) => {
|
|
373
|
-
caught = e;
|
|
374
|
-
});
|
|
375
|
-
// Only `*_FORBIDDEN` authorization denials are reclassified; a real backend
|
|
376
|
-
// failure must still surface loudly so it is not masked as an expected skip.
|
|
377
|
-
expect(isAccessDenied(caught)).toBe(false);
|
|
378
|
-
expect((caught as Error).message).toMatch(/denied for secret\/x.*PRESIGN_INTERNAL/);
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it("throws when the PUT itself fails", async () => {
|
|
382
|
-
const { vault, setPresign } = makeVault();
|
|
383
|
-
setPresign([{ key: "k", op: "put", url: "https://s3/put" }]);
|
|
384
|
-
fetchMock.mockResolvedValue(new Response("AccessDenied", { status: 403 }));
|
|
385
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
386
|
-
await expect(
|
|
387
|
-
io.putObject({ key: "k", body: Buffer.from("z"), contentType: "x" }),
|
|
388
|
-
).rejects.toThrow(/presigned PUT failed for k: 403/);
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it("F01: fails closed when a fenced PUT presign omits If-Match", async () => {
|
|
392
|
-
const previous = process.env.HQ_PRESIGN_FENCE_STRICT;
|
|
393
|
-
process.env.HQ_PRESIGN_FENCE_STRICT = "true";
|
|
394
|
-
try {
|
|
395
|
-
const { vault, setPresign } = makeVault();
|
|
396
|
-
setPresign([
|
|
397
|
-
{
|
|
398
|
-
key: "stale.md",
|
|
399
|
-
op: "put",
|
|
400
|
-
url: "https://s3/unfenced-put",
|
|
401
|
-
headers: { "content-type": "text/markdown" },
|
|
402
|
-
},
|
|
403
|
-
]);
|
|
404
|
-
fetchMock.mockResolvedValue(
|
|
405
|
-
new Response(null, { status: 200, headers: { etag: '"v2"' } }),
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
409
|
-
await expect(
|
|
410
|
-
io.putObject({
|
|
411
|
-
key: "stale.md",
|
|
412
|
-
body: Buffer.from("old bytes"),
|
|
413
|
-
contentType: "text/markdown",
|
|
414
|
-
ifMatch: '"v1"',
|
|
415
|
-
}),
|
|
416
|
-
).rejects.toThrow(/if-match|condition|precondition/i);
|
|
417
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
418
|
-
} finally {
|
|
419
|
-
if (previous === undefined) {
|
|
420
|
-
delete process.env.HQ_PRESIGN_FENCE_STRICT;
|
|
421
|
-
} else {
|
|
422
|
-
process.env.HQ_PRESIGN_FENCE_STRICT = previous;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it("F01: does not satisfy a fenced PUT with an unfenced primed URL", async () => {
|
|
428
|
-
const presignCalls: Array<Parameters<PresignTransportClient["presign"]>[0]> = [];
|
|
429
|
-
const vault: PresignTransportClient = {
|
|
430
|
-
presign: async (input) => {
|
|
431
|
-
presignCalls.push(input);
|
|
432
|
-
const isFenced = input.keys.some((k) => k.ifNoneMatch === "*");
|
|
433
|
-
return {
|
|
434
|
-
results: input.keys.map((k): PresignResultRow => ({
|
|
435
|
-
key: k.key,
|
|
436
|
-
op: k.op ?? input.op ?? "put",
|
|
437
|
-
url: isFenced ? "https://s3/fenced-put" : "https://s3/unfenced-put",
|
|
438
|
-
headers: isFenced
|
|
439
|
-
? { "content-type": "text/plain", "if-none-match": "*" }
|
|
440
|
-
: { "content-type": "text/plain" },
|
|
441
|
-
expiresIn: 900,
|
|
442
|
-
})),
|
|
443
|
-
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
444
|
-
};
|
|
445
|
-
},
|
|
446
|
-
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
447
|
-
};
|
|
448
|
-
fetchMock.mockResolvedValue(
|
|
449
|
-
new Response(null, { status: 200, headers: { etag: '"created"' } }),
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
453
|
-
await io.prime("put", [{ key: "new.md", op: "put", contentType: "text/plain" }]);
|
|
454
|
-
const afterPrime = presignCalls.length;
|
|
455
|
-
|
|
456
|
-
await io.putObject({
|
|
457
|
-
key: "new.md",
|
|
458
|
-
body: Buffer.from("new bytes"),
|
|
459
|
-
contentType: "text/plain",
|
|
460
|
-
ifNoneMatch: "*",
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
expect(presignCalls).toHaveLength(afterPrime + 1);
|
|
464
|
-
expect(presignCalls[afterPrime].keys[0]).toMatchObject({
|
|
465
|
-
key: "new.md",
|
|
466
|
-
op: "put",
|
|
467
|
-
ifNoneMatch: "*",
|
|
468
|
-
});
|
|
469
|
-
const [url, init] = fetchMock.mock.calls[0];
|
|
470
|
-
expect(url).toBe("https://s3/fenced-put");
|
|
471
|
-
expect(init.headers).toEqual({
|
|
472
|
-
"content-type": "text/plain",
|
|
473
|
-
"if-none-match": "*",
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it("forwards the conditional-write fence on the presign request (ifMatch stripped, ifNoneMatch verbatim)", async () => {
|
|
478
|
-
// The server signs If-Match/If-None-Match into the URL (hq-pro follow-up)
|
|
479
|
-
// and echoes the headers for replay; the client's job is to ASK. Servers
|
|
480
|
-
// that predate the fields ignore them — never broken, just unconditional.
|
|
481
|
-
const { vault, presignCalls, setPresign } = makeVault();
|
|
482
|
-
setPresign([{ key: "fenced.md", op: "put", url: "https://s3/put-url" }]);
|
|
483
|
-
fetchMock.mockResolvedValue(
|
|
484
|
-
new Response(null, { status: 200, headers: { etag: '"v2"' } }),
|
|
485
|
-
);
|
|
486
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
487
|
-
await io.putObject({
|
|
488
|
-
key: "fenced.md",
|
|
489
|
-
body: Buffer.from("x"),
|
|
490
|
-
contentType: "text/markdown",
|
|
491
|
-
ifMatch: '"v1"',
|
|
492
|
-
});
|
|
493
|
-
expect(presignCalls[0].keys[0]).toMatchObject({
|
|
494
|
-
key: "fenced.md",
|
|
495
|
-
op: "put",
|
|
496
|
-
ifMatch: "v1", // quotes stripped on the wire; server re-quotes when signing
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
await io.putObject({
|
|
500
|
-
key: "fresh.md",
|
|
501
|
-
body: Buffer.from("y"),
|
|
502
|
-
contentType: "text/markdown",
|
|
503
|
-
ifNoneMatch: "*",
|
|
504
|
-
});
|
|
505
|
-
expect(presignCalls[1].keys[0]).toMatchObject({
|
|
506
|
-
key: "fresh.md",
|
|
507
|
-
op: "put",
|
|
508
|
-
ifNoneMatch: "*",
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
it("maps a 412 PUT response to name:PreconditionFailed (the fence fired — conflict, not failure)", async () => {
|
|
513
|
-
const { vault, setPresign } = makeVault();
|
|
514
|
-
setPresign([{ key: "raced.md", op: "put", url: "https://s3/put-url" }]);
|
|
515
|
-
fetchMock.mockResolvedValue(
|
|
516
|
-
new Response("PreconditionFailed", { status: 412 }),
|
|
517
|
-
);
|
|
518
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
519
|
-
await expect(
|
|
520
|
-
io.putObject({
|
|
521
|
-
key: "raced.md",
|
|
522
|
-
body: Buffer.from("z"),
|
|
523
|
-
contentType: "text/plain",
|
|
524
|
-
ifMatch: "old-etag",
|
|
525
|
-
}),
|
|
526
|
-
).rejects.toMatchObject({ name: "PreconditionFailed" });
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
describe("PresignObjectIO.getObject", () => {
|
|
531
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
532
|
-
beforeEach(() => {
|
|
533
|
-
fetchMock = vi.fn();
|
|
534
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
535
|
-
});
|
|
536
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
537
|
-
|
|
538
|
-
it("returns body bytes + x-amz-meta-* metadata", async () => {
|
|
539
|
-
const { vault, presignCalls, setPresign } = makeVault();
|
|
540
|
-
setPresign([{ key: "shared/a.md", op: "get", url: "https://s3/get" }]);
|
|
541
|
-
fetchMock.mockResolvedValue(
|
|
542
|
-
new Response(Buffer.from("file-bytes"), {
|
|
543
|
-
status: 200,
|
|
544
|
-
headers: {
|
|
545
|
-
"x-amz-meta-created-by": "me@getindigo.ai",
|
|
546
|
-
"x-amz-meta-hq-mode": "640",
|
|
547
|
-
"content-type": "text/markdown",
|
|
548
|
-
},
|
|
549
|
-
}),
|
|
550
|
-
);
|
|
551
|
-
|
|
552
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
553
|
-
const res = await io.getObject("shared/a.md");
|
|
554
|
-
|
|
555
|
-
expect(presignCalls[0].op).toBe("get");
|
|
556
|
-
expect(res.body.toString("utf-8")).toBe("file-bytes");
|
|
557
|
-
expect(res.metadata).toEqual({
|
|
558
|
-
"created-by": "me@getindigo.ai",
|
|
559
|
-
"hq-mode": "640",
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
it("drains the injected transport body instead of returning empty content", async () => {
|
|
564
|
-
const { vault, setPresign } = makeVault();
|
|
565
|
-
setPresign([{ key: "shared/a.md", op: "get", url: "https://s3/get" }]);
|
|
566
|
-
const transportGet = vi.fn(async () => ({
|
|
567
|
-
status: 200,
|
|
568
|
-
headers: new Headers({ "x-amz-meta-source": "transport" }),
|
|
569
|
-
body: (async function* (): AsyncIterable<Uint8Array> {
|
|
570
|
-
yield Buffer.from("transport-bytes");
|
|
571
|
-
})(),
|
|
572
|
-
destroy: () => undefined,
|
|
573
|
-
}));
|
|
574
|
-
setPresignedGetTransportForTesting({ get: transportGet });
|
|
575
|
-
|
|
576
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
577
|
-
const res = await io.getObject("shared/a.md");
|
|
578
|
-
|
|
579
|
-
expect(res.body.toString("utf-8")).toBe("transport-bytes");
|
|
580
|
-
expect(res.metadata).toEqual({ source: "transport" });
|
|
581
|
-
expect(transportGet).toHaveBeenCalledWith("https://s3/get", undefined);
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
it("throws a NotFound-named error on 404 (so s3.ts catch sites match)", async () => {
|
|
585
|
-
const { vault, setPresign } = makeVault();
|
|
586
|
-
setPresign([{ key: "gone", op: "get", url: "https://s3/get" }]);
|
|
587
|
-
fetchMock.mockResolvedValue(new Response("", { status: 404 }));
|
|
588
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
589
|
-
await expect(io.getObject("gone")).rejects.toMatchObject({
|
|
590
|
-
name: "NotFound",
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
describe("PresignObjectIO.listObjects", () => {
|
|
596
|
-
it("maps listFiles rows into the RemoteObject shape (etag, Date)", async () => {
|
|
597
|
-
const { vault, setList } = makeVault();
|
|
598
|
-
setList({
|
|
599
|
-
objects: [
|
|
600
|
-
{
|
|
601
|
-
key: "shared/a.md",
|
|
602
|
-
size: 12,
|
|
603
|
-
lastModified: "2026-01-01T00:00:00.000Z",
|
|
604
|
-
etag: "deadbeef",
|
|
605
|
-
permission: "read",
|
|
606
|
-
},
|
|
607
|
-
{
|
|
608
|
-
key: "shared/b.md",
|
|
609
|
-
size: 0,
|
|
610
|
-
lastModified: null,
|
|
611
|
-
etag: null,
|
|
612
|
-
permission: "write",
|
|
613
|
-
},
|
|
614
|
-
],
|
|
615
|
-
cursor: "next-token",
|
|
616
|
-
truncated: true,
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
620
|
-
const res = await io.listObjects({ prefix: "shared/" });
|
|
621
|
-
|
|
622
|
-
expect(res.nextContinuationToken).toBe("next-token");
|
|
623
|
-
expect(res.objects[0]).toEqual({
|
|
624
|
-
key: "shared/a.md",
|
|
625
|
-
size: 12,
|
|
626
|
-
lastModified: new Date("2026-01-01T00:00:00.000Z"),
|
|
627
|
-
etag: "deadbeef",
|
|
628
|
-
});
|
|
629
|
-
// null etag → "" ; null lastModified → a Date (not crash).
|
|
630
|
-
expect(res.objects[1].etag).toBe("");
|
|
631
|
-
expect(res.objects[1].lastModified).toBeInstanceOf(Date);
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
it("exhausted listing yields undefined nextContinuationToken", async () => {
|
|
635
|
-
const { vault, setList } = makeVault();
|
|
636
|
-
setList({ objects: [], cursor: null, truncated: false });
|
|
637
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
638
|
-
const res = await io.listObjects({});
|
|
639
|
-
expect(res.nextContinuationToken).toBeUndefined();
|
|
640
|
-
});
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
describe("PresignObjectIO.deleteObject", () => {
|
|
644
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
645
|
-
beforeEach(() => {
|
|
646
|
-
fetchMock = vi.fn();
|
|
647
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
648
|
-
});
|
|
649
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
650
|
-
|
|
651
|
-
it("sends op:delete and DELETEs the signed URL", async () => {
|
|
652
|
-
const { vault, presignCalls, setPresign } = makeVault();
|
|
653
|
-
setPresign([{ key: "shared/a.md", op: "delete", url: "https://s3/del" }]);
|
|
654
|
-
fetchMock.mockResolvedValue(new Response(null, { status: 204 }));
|
|
655
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
656
|
-
await io.deleteObject("shared/a.md");
|
|
657
|
-
expect(presignCalls[0].op).toBe("delete");
|
|
658
|
-
expect(fetchMock.mock.calls[0][1].method).toBe("DELETE");
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
it("treats a 404 DELETE as success (idempotent)", async () => {
|
|
662
|
-
const { vault, setPresign } = makeVault();
|
|
663
|
-
setPresign([{ key: "gone", op: "delete", url: "https://s3/del" }]);
|
|
664
|
-
fetchMock.mockResolvedValue(new Response("", { status: 404 }));
|
|
665
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
666
|
-
await expect(io.deleteObject("gone")).resolves.toBeUndefined();
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
describe("PresignObjectIO.headObject", () => {
|
|
671
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
672
|
-
beforeEach(() => {
|
|
673
|
-
fetchMock = vi.fn();
|
|
674
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
675
|
-
});
|
|
676
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
677
|
-
|
|
678
|
-
it("reads headers (etag/size/lastModified/metadata) via a presigned GET", async () => {
|
|
679
|
-
const { vault, setPresign } = makeVault();
|
|
680
|
-
setPresign([{ key: "shared/a.md", op: "get", url: "https://s3/get" }]);
|
|
681
|
-
fetchMock.mockResolvedValue(
|
|
682
|
-
new Response(Buffer.from("ignored-body"), {
|
|
683
|
-
status: 200,
|
|
684
|
-
headers: {
|
|
685
|
-
etag: '"feedface"',
|
|
686
|
-
"content-length": "123",
|
|
687
|
-
"last-modified": "Wed, 01 Jan 2026 00:00:00 GMT",
|
|
688
|
-
"x-amz-meta-created-at": "2026-01-01T00:00:00.000Z",
|
|
689
|
-
},
|
|
690
|
-
}),
|
|
691
|
-
);
|
|
692
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
693
|
-
const head = await io.headObject("shared/a.md");
|
|
694
|
-
expect(head).not.toBeNull();
|
|
695
|
-
expect(head!.etag).toBe("feedface");
|
|
696
|
-
expect(head!.size).toBe(123);
|
|
697
|
-
expect(head!.metadata).toEqual({
|
|
698
|
-
"created-at": "2026-01-01T00:00:00.000Z",
|
|
699
|
-
});
|
|
700
|
-
expect(head!.lastModified.getTime()).toBe(
|
|
701
|
-
Date.parse("Wed, 01 Jan 2026 00:00:00 GMT"),
|
|
702
|
-
);
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
it("returns null on 404", async () => {
|
|
706
|
-
const { vault, setPresign } = makeVault();
|
|
707
|
-
setPresign([{ key: "gone", op: "get", url: "https://s3/get" }]);
|
|
708
|
-
fetchMock.mockResolvedValue(new Response("", { status: 404 }));
|
|
709
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
710
|
-
expect(await io.headObject("gone")).toBeNull();
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
it("returns null on a server-confirmed FILES_PRESIGN_NOT_FOUND (absence, not denial — no GET issued)", async () => {
|
|
714
|
-
// The presign lambda HEAD'd S3 and confirmed absence. Unlike a read
|
|
715
|
-
// DENIAL (Forbidden, below), this is unambiguous "object missing", so
|
|
716
|
-
// headObject reports absent (null) and the push creates the new object —
|
|
717
|
-
// never reaching a 403-masked presigned GET.
|
|
718
|
-
const { vault, setPresign } = makeVault();
|
|
719
|
-
setPresign([
|
|
720
|
-
{
|
|
721
|
-
key: "new.md",
|
|
722
|
-
op: "get",
|
|
723
|
-
error: "Object not found: 'new.md'",
|
|
724
|
-
code: "FILES_PRESIGN_NOT_FOUND",
|
|
725
|
-
},
|
|
726
|
-
]);
|
|
727
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
728
|
-
expect(await io.headObject("new.md")).toBeNull();
|
|
729
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
it("throws Forbidden when presign denies the key — denial is NOT absence", async () => {
|
|
733
|
-
// Regression: pre-fix this returned null ("absent"), which made
|
|
734
|
-
// share.ts's push guard (`if (remoteMeta)`) skip every conflict check
|
|
735
|
-
// and issue an unconditional PUT — a transient denial mid-pass silently
|
|
736
|
-
// clobbered newer remote bytes (2026-06-10..12 vault regression storm).
|
|
737
|
-
const { vault, setPresign } = makeVault();
|
|
738
|
-
setPresign([{ key: "secret/x", op: "get", error: "forbidden" }]);
|
|
739
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
740
|
-
await expect(io.headObject("secret/x")).rejects.toMatchObject({
|
|
741
|
-
name: "Forbidden",
|
|
742
|
-
});
|
|
743
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
it("throws Forbidden on a presigned-GET 403 — same SDK-parity contract", async () => {
|
|
747
|
-
// Expired presigned URL, expired signing creds, KMS or bucket-policy
|
|
748
|
-
// denial all surface as 403 on the signed GET. Unknown state — must
|
|
749
|
-
// never read as "object missing".
|
|
750
|
-
const { vault, setPresign } = makeVault();
|
|
751
|
-
setPresign([{ key: "shared/a.md", op: "get", url: "https://s3/get" }]);
|
|
752
|
-
fetchMock.mockResolvedValue(new Response("AccessDenied", { status: 403 }));
|
|
753
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
754
|
-
await expect(io.headObject("shared/a.md")).rejects.toMatchObject({
|
|
755
|
-
name: "Forbidden",
|
|
756
|
-
});
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
it("still returns null on a definitive 404 (key truly absent)", async () => {
|
|
760
|
-
const { vault, setPresign } = makeVault();
|
|
761
|
-
setPresign([{ key: "gone2", op: "get", url: "https://s3/get" }]);
|
|
762
|
-
fetchMock.mockResolvedValue(new Response("", { status: 404 }));
|
|
763
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
764
|
-
expect(await io.headObject("gone2")).toBeNull();
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
/**
|
|
769
|
-
* Echo vault: presign returns one signed row per requested key (url derived
|
|
770
|
-
* from op+key) and records call count + total keys, so prime/cache tests can
|
|
771
|
-
* assert "N files → ceil(N/100) presign calls, then zero".
|
|
772
|
-
*/
|
|
773
|
-
function makeEchoVault() {
|
|
774
|
-
let calls = 0;
|
|
775
|
-
let totalKeys = 0;
|
|
776
|
-
const vault: PresignTransportClient = {
|
|
777
|
-
presign: async (input) => {
|
|
778
|
-
calls++;
|
|
779
|
-
totalKeys += input.keys.length;
|
|
780
|
-
return {
|
|
781
|
-
results: input.keys.map((k) => ({
|
|
782
|
-
key: k.key,
|
|
783
|
-
op: k.op ?? input.op ?? "get",
|
|
784
|
-
url: `https://signed/${k.op ?? input.op}/${encodeURIComponent(k.key)}`,
|
|
785
|
-
...(k.op === "put" || input.op === "put"
|
|
786
|
-
? { headers: { "content-type": "text/plain" } }
|
|
787
|
-
: {}),
|
|
788
|
-
expiresIn: input.expiresIn ?? 900,
|
|
789
|
-
})),
|
|
790
|
-
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
791
|
-
};
|
|
792
|
-
},
|
|
793
|
-
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
794
|
-
};
|
|
795
|
-
return {
|
|
796
|
-
vault,
|
|
797
|
-
calls: () => calls,
|
|
798
|
-
totalKeys: () => totalKeys,
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
describe("PresignObjectIO.prime — batch URL cache", () => {
|
|
803
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
804
|
-
beforeEach(() => {
|
|
805
|
-
fetchMock = vi.fn(async () => new Response(Buffer.from("x"), { status: 200 }));
|
|
806
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
807
|
-
});
|
|
808
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
809
|
-
|
|
810
|
-
it("chunks at 1000 keys per presign call (the server batch cap)", async () => {
|
|
811
|
-
const { vault, calls, totalKeys } = makeEchoVault();
|
|
812
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
813
|
-
const keys = Array.from({ length: 2500 }, (_, i) => ({ key: `k${i}` }));
|
|
814
|
-
await io.prime("get", keys);
|
|
815
|
-
expect(calls()).toBe(3); // 1000 + 1000 + 500
|
|
816
|
-
expect(totalKeys()).toBe(2500);
|
|
817
|
-
});
|
|
818
|
-
|
|
819
|
-
it("primed getObject reuses the cache — zero extra presign calls", async () => {
|
|
820
|
-
const { vault, calls } = makeEchoVault();
|
|
821
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
822
|
-
const keys = Array.from({ length: 5 }, (_, i) => ({ key: `f${i}` }));
|
|
823
|
-
await io.prime("get", keys);
|
|
824
|
-
const afterPrime = calls(); // 1 chunk
|
|
825
|
-
for (const k of keys) await io.getObject(k.key);
|
|
826
|
-
expect(calls()).toBe(afterPrime); // no new presign calls
|
|
827
|
-
expect(fetchMock).toHaveBeenCalledTimes(5); // but the bytes were fetched
|
|
828
|
-
// The fetched URL is the primed (cached) one.
|
|
829
|
-
expect(fetchMock.mock.calls[0][0]).toBe("https://signed/get/f0");
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
it("F21: consumes primed GET URLs instead of retaining them", async () => {
|
|
833
|
-
const { vault, calls } = makeEchoVault();
|
|
834
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
835
|
-
await io.prime("get", [{ key: "single" }]);
|
|
836
|
-
const afterPrime = calls();
|
|
837
|
-
|
|
838
|
-
await io.getObject("single");
|
|
839
|
-
expect(calls()).toBe(afterPrime);
|
|
840
|
-
|
|
841
|
-
await io.getObject("single");
|
|
842
|
-
expect(calls()).toBe(afterPrime + 1);
|
|
843
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
844
|
-
});
|
|
845
|
-
|
|
846
|
-
it("R-F21: reuses a primed GET for later HEAD and clears stale primed PUT on fenced PUT", async () => {
|
|
847
|
-
fetchMock.mockImplementation(async () => (
|
|
848
|
-
new Response(Buffer.from("body"), {
|
|
849
|
-
status: 200,
|
|
850
|
-
headers: {
|
|
851
|
-
etag: '"etag-1"',
|
|
852
|
-
"content-length": "4",
|
|
853
|
-
"last-modified": "Wed, 01 Jan 2026 00:00:00 GMT",
|
|
854
|
-
},
|
|
855
|
-
})
|
|
856
|
-
));
|
|
857
|
-
const { vault, calls } = makeEchoVault();
|
|
858
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
859
|
-
|
|
860
|
-
await io.prime("get", [{ key: "doc.md" }]);
|
|
861
|
-
const afterGetPrime = calls();
|
|
862
|
-
const got = await io.getObject("doc.md");
|
|
863
|
-
expect(got.body.toString("utf-8")).toBe("body");
|
|
864
|
-
|
|
865
|
-
const head = await io.headObject("doc.md");
|
|
866
|
-
expect(head?.etag).toBe("etag-1");
|
|
867
|
-
expect(calls()).toBe(afterGetPrime);
|
|
868
|
-
expect(fetchMock.mock.calls[0][0]).toBe("https://signed/get/doc.md");
|
|
869
|
-
expect(fetchMock.mock.calls[1][0]).toBe("https://signed/get/doc.md");
|
|
870
|
-
|
|
871
|
-
await io.prime("put", [
|
|
872
|
-
{ key: "stale.md", op: "put", contentType: "text/plain" },
|
|
873
|
-
]);
|
|
874
|
-
expect(io.hasPrimedPut("stale.md")).toBe(true);
|
|
875
|
-
const afterPutPrime = calls();
|
|
876
|
-
|
|
877
|
-
await io.putObject({
|
|
878
|
-
key: "stale.md",
|
|
879
|
-
body: Buffer.from("new body"),
|
|
880
|
-
contentType: "text/plain",
|
|
881
|
-
ifMatch: "old-etag",
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
expect(calls()).toBe(afterPutPrime + 1);
|
|
885
|
-
expect(io.hasPrimedPut("stale.md")).toBe(false);
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
it("primed GET cache also serves headObject (HEAD reuses GET URLs)", async () => {
|
|
889
|
-
const { vault, calls } = makeEchoVault();
|
|
890
|
-
fetchMock.mockResolvedValue(
|
|
891
|
-
new Response(Buffer.from(""), {
|
|
892
|
-
status: 200,
|
|
893
|
-
headers: { etag: '"e"', "content-length": "0" },
|
|
894
|
-
}),
|
|
895
|
-
);
|
|
896
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
897
|
-
await io.prime("get", [{ key: "doc.md" }]);
|
|
898
|
-
const afterPrime = calls();
|
|
899
|
-
const head = await io.headObject("doc.md");
|
|
900
|
-
expect(head).not.toBeNull();
|
|
901
|
-
expect(calls()).toBe(afterPrime); // head used the cached GET url, no presign
|
|
902
|
-
});
|
|
903
|
-
|
|
904
|
-
it("a key NOT primed falls back to a single presign", async () => {
|
|
905
|
-
const { vault, calls } = makeEchoVault();
|
|
906
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
907
|
-
await io.prime("get", [{ key: "primed" }]);
|
|
908
|
-
const afterPrime = calls();
|
|
909
|
-
await io.getObject("not-primed");
|
|
910
|
-
expect(calls()).toBe(afterPrime + 1);
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
it("empty prime is a no-op (no presign call)", async () => {
|
|
914
|
-
const { vault, calls } = makeEchoVault();
|
|
915
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
916
|
-
await io.prime("get", []);
|
|
917
|
-
expect(calls()).toBe(0);
|
|
918
|
-
});
|
|
919
|
-
|
|
920
|
-
it("a chunk that throws doesn't fail prime; those keys fall back per-file", async () => {
|
|
921
|
-
let calls = 0;
|
|
922
|
-
const vault: PresignTransportClient = {
|
|
923
|
-
presign: async (input) => {
|
|
924
|
-
calls++;
|
|
925
|
-
if (calls === 1) throw new Error("transient");
|
|
926
|
-
return {
|
|
927
|
-
results: input.keys.map((k) => ({
|
|
928
|
-
key: k.key,
|
|
929
|
-
op: "get" as const,
|
|
930
|
-
url: `https://signed/get/${k.key}`,
|
|
931
|
-
expiresIn: 900,
|
|
932
|
-
})),
|
|
933
|
-
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
934
|
-
};
|
|
935
|
-
},
|
|
936
|
-
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
937
|
-
};
|
|
938
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
939
|
-
// Single chunk that throws — prime resolves anyway, key stays uncached.
|
|
940
|
-
await expect(io.prime("get", [{ key: "k" }])).resolves.toBeUndefined();
|
|
941
|
-
// getObject then single-presigns (call #2 succeeds).
|
|
942
|
-
await io.getObject("k");
|
|
943
|
-
expect(calls).toBe(2);
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
|
|
947
|
-
describe("presignObjectIOFactory — memoization", () => {
|
|
948
|
-
afterEach(() => setObjectIOFactory(null));
|
|
949
|
-
it("returns the SAME instance per companyUid so prime + transfer share a cache", () => {
|
|
950
|
-
const { vault } = makeEchoVault();
|
|
951
|
-
const factory = presignObjectIOFactory(vault);
|
|
952
|
-
const a1 = factory(ctx());
|
|
953
|
-
const a2 = factory(ctx());
|
|
954
|
-
expect(a1).toBe(a2); // same company → same instance
|
|
955
|
-
const other = factory({ ...ctx(), uid: "cmp_other" });
|
|
956
|
-
expect(other).not.toBe(a1); // different company → different instance
|
|
957
|
-
});
|
|
958
|
-
});
|
|
959
|
-
|
|
960
|
-
describe("PresignObjectIO — transient-failure retry (SDK parity)", () => {
|
|
961
|
-
afterEach(() => {
|
|
962
|
-
vi.useRealTimers();
|
|
963
|
-
vi.unstubAllGlobals();
|
|
964
|
-
});
|
|
965
|
-
|
|
966
|
-
it("retries a transient 503 then succeeds", async () => {
|
|
967
|
-
vi.useFakeTimers();
|
|
968
|
-
const { vault, setPresign } = makeVault();
|
|
969
|
-
setPresign([{ key: "k", op: "get", url: "https://s3/get" }]);
|
|
970
|
-
const fetchMock = vi
|
|
971
|
-
.fn()
|
|
972
|
-
.mockResolvedValueOnce(new Response("SlowDown", { status: 503 }))
|
|
973
|
-
.mockResolvedValueOnce(new Response(Buffer.from("ok"), { status: 200 }));
|
|
974
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
975
|
-
|
|
976
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
977
|
-
const pr = io.getObject("k");
|
|
978
|
-
await vi.runAllTimersAsync();
|
|
979
|
-
const res = await pr;
|
|
980
|
-
expect(res.body.toString("utf-8")).toBe("ok");
|
|
981
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
982
|
-
});
|
|
983
|
-
|
|
984
|
-
it("retries a network error (fetch throws) then succeeds", async () => {
|
|
985
|
-
vi.useFakeTimers();
|
|
986
|
-
const { vault, setPresign } = makeVault();
|
|
987
|
-
setPresign([{ key: "k", op: "get", url: "https://s3/get" }]);
|
|
988
|
-
const fetchMock = vi
|
|
989
|
-
.fn()
|
|
990
|
-
.mockRejectedValueOnce(new Error("socket hang up"))
|
|
991
|
-
.mockResolvedValueOnce(new Response(Buffer.from("ok"), { status: 200 }));
|
|
992
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
993
|
-
|
|
994
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
995
|
-
const pr = io.getObject("k");
|
|
996
|
-
await vi.runAllTimersAsync();
|
|
997
|
-
const res = await pr;
|
|
998
|
-
expect(res.body.toString("utf-8")).toBe("ok");
|
|
999
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
it("throws after exhausting retries on persistent 503 (initial + 3 retries = 4)", async () => {
|
|
1003
|
-
vi.useFakeTimers();
|
|
1004
|
-
const { vault, setPresign } = makeVault();
|
|
1005
|
-
setPresign([{ key: "k", op: "get", url: "https://s3/get" }]);
|
|
1006
|
-
const fetchMock = vi.fn().mockResolvedValue(new Response("err", { status: 503 }));
|
|
1007
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
1008
|
-
|
|
1009
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
1010
|
-
const pr = io.getObject("k").catch((e) => e);
|
|
1011
|
-
await vi.runAllTimersAsync();
|
|
1012
|
-
const err = await pr;
|
|
1013
|
-
expect(String(err)).toMatch(/503/);
|
|
1014
|
-
expect(fetchMock).toHaveBeenCalledTimes(4);
|
|
1015
|
-
});
|
|
1016
|
-
|
|
1017
|
-
it("does NOT retry a definitive 404", async () => {
|
|
1018
|
-
const { vault, setPresign } = makeVault();
|
|
1019
|
-
setPresign([{ key: "gone", op: "get", url: "https://s3/get" }]);
|
|
1020
|
-
const fetchMock = vi.fn().mockResolvedValue(new Response("", { status: 404 }));
|
|
1021
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
1022
|
-
|
|
1023
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
1024
|
-
await expect(io.getObject("gone")).rejects.toMatchObject({ name: "NotFound" });
|
|
1025
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
1026
|
-
});
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
|
-
import { VaultClientError } from "./vault-client.js";
|
|
1030
|
-
|
|
1031
|
-
describe("PresignObjectIO — 429 circuit breaker", () => {
|
|
1032
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
1033
|
-
|
|
1034
|
-
it("trips on a 429: uncached keys fail fast (no further presign), primed keys still work", async () => {
|
|
1035
|
-
let presignCalls = 0;
|
|
1036
|
-
const vault: PresignTransportClient = {
|
|
1037
|
-
presign: async (input) => {
|
|
1038
|
-
presignCalls++;
|
|
1039
|
-
if (input.keys.some((k) => k.key === "primed")) {
|
|
1040
|
-
return {
|
|
1041
|
-
results: input.keys.map((k) => ({
|
|
1042
|
-
key: k.key,
|
|
1043
|
-
op: k.op ?? "get",
|
|
1044
|
-
url: `https://s/${k.key}`,
|
|
1045
|
-
expiresIn: 900,
|
|
1046
|
-
})),
|
|
1047
|
-
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
throw new VaultClientError("Rate limit exceeded: 100 requests per hour", 429);
|
|
1051
|
-
},
|
|
1052
|
-
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
1053
|
-
};
|
|
1054
|
-
vi.stubGlobal(
|
|
1055
|
-
"fetch",
|
|
1056
|
-
vi.fn(async () => new Response(Buffer.from("x"), { status: 200 })),
|
|
1057
|
-
);
|
|
1058
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
1059
|
-
await io.prime("get", [{ key: "primed" }]); // caches "primed"
|
|
1060
|
-
|
|
1061
|
-
await expect(io.getObject("uncached1")).rejects.toMatchObject({
|
|
1062
|
-
name: "RateLimited",
|
|
1063
|
-
});
|
|
1064
|
-
const afterTrip = presignCalls;
|
|
1065
|
-
// Second uncached key fails fast — NO new presign call.
|
|
1066
|
-
await expect(io.getObject("uncached2")).rejects.toMatchObject({
|
|
1067
|
-
name: "RateLimited",
|
|
1068
|
-
});
|
|
1069
|
-
expect(presignCalls).toBe(afterTrip);
|
|
1070
|
-
// The primed key still resolves from cache (no presign needed).
|
|
1071
|
-
const r = await io.getObject("primed");
|
|
1072
|
-
expect(r.body.toString("utf-8")).toBe("x");
|
|
1073
|
-
});
|
|
1074
|
-
|
|
1075
|
-
it("prime stops minting once a chunk 429s (breaker trips, remaining chunks skipped)", async () => {
|
|
1076
|
-
let calls = 0;
|
|
1077
|
-
const vault: PresignTransportClient = {
|
|
1078
|
-
presign: async () => {
|
|
1079
|
-
calls++;
|
|
1080
|
-
throw new VaultClientError("rate", 429);
|
|
1081
|
-
},
|
|
1082
|
-
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
1083
|
-
};
|
|
1084
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
1085
|
-
// 10 chunks (10k keys @ 1000); concurrency is 4, so at most the first
|
|
1086
|
-
// concurrent batch fires before the breaker trips — far fewer than 10.
|
|
1087
|
-
await io.prime(
|
|
1088
|
-
"get",
|
|
1089
|
-
Array.from({ length: 10_000 }, (_, i) => ({ key: `k${i}` })),
|
|
1090
|
-
);
|
|
1091
|
-
expect(calls).toBeLessThanOrEqual(4);
|
|
1092
|
-
expect(calls).toBeLessThan(10);
|
|
1093
|
-
});
|
|
1094
|
-
});
|
|
1095
|
-
|
|
1096
|
-
describe("PresignObjectIO.hasPrimedPut", () => {
|
|
1097
|
-
it("reflects a put prime", async () => {
|
|
1098
|
-
const { vault } = makeEchoVault();
|
|
1099
|
-
const io = new PresignObjectIO(vault, COMPANY);
|
|
1100
|
-
expect(io.hasPrimedPut("k")).toBe(false);
|
|
1101
|
-
await io.prime("put", [
|
|
1102
|
-
{ key: "k", op: "put", contentType: "text/plain", metadata: { "hq-mode": "644" } },
|
|
1103
|
-
]);
|
|
1104
|
-
expect(io.hasPrimedPut("k")).toBe(true);
|
|
1105
|
-
// A different, unprimed key stays false.
|
|
1106
|
-
expect(io.hasPrimedPut("other")).toBe(false);
|
|
1107
|
-
});
|
|
1108
|
-
});
|
|
1109
|
-
|
|
1110
|
-
describe("presignObjectIOFactory — personal vaults route to S3 SDK", () => {
|
|
1111
|
-
it("routes a person entity (prs_*) to S3SdkObjectIO, a company (cmp_*) to presign", () => {
|
|
1112
|
-
const { vault } = makeEchoVault();
|
|
1113
|
-
const factory = presignObjectIOFactory(vault);
|
|
1114
|
-
const company = factory({ ...ctx(), uid: "cmp_real" });
|
|
1115
|
-
const personal = factory({ ...ctx(), uid: "prs_real" });
|
|
1116
|
-
expect(company).toBeInstanceOf(PresignObjectIO);
|
|
1117
|
-
// Personal vaults use the membership-less vend-self model; the
|
|
1118
|
-
// membership-gated presign endpoints 403 for them, so they stay on STS.
|
|
1119
|
-
expect(personal).toBeInstanceOf(S3SdkObjectIO);
|
|
1120
|
-
});
|
|
1121
|
-
});
|
|
1122
|
-
|
|
1123
|
-
describe("PresignObjectIO — core HTTP presigned GET", () => {
|
|
1124
|
-
function streamingVault(baseUrl: string): PresignTransportClient {
|
|
1125
|
-
return {
|
|
1126
|
-
presign: async (input) => ({
|
|
1127
|
-
results: input.keys.map((key) => ({
|
|
1128
|
-
key: key.key,
|
|
1129
|
-
op: "get" as const,
|
|
1130
|
-
url: `${baseUrl}/${key.key}`,
|
|
1131
|
-
})),
|
|
1132
|
-
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
1133
|
-
}),
|
|
1134
|
-
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
1135
|
-
};
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
it("destroys an early-exit response and rejects a FIN-short body", async () => {
|
|
1139
|
-
setPresignedGetTransportForTesting(null);
|
|
1140
|
-
let responseClosed: Promise<unknown> | undefined;
|
|
1141
|
-
const server = http.createServer((req, res) => {
|
|
1142
|
-
if (req.url === "/short") {
|
|
1143
|
-
res.writeHead(200, { "content-length": "10" });
|
|
1144
|
-
res.end("short");
|
|
1145
|
-
return;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
res.writeHead(200, { "content-length": "131072" });
|
|
1149
|
-
res.write(Buffer.alloc(65_536, 1));
|
|
1150
|
-
responseClosed = once(res, "close");
|
|
1151
|
-
const finish = setTimeout(() => res.end(Buffer.alloc(65_536, 2)), 1_000);
|
|
1152
|
-
res.once("close", () => clearTimeout(finish));
|
|
1153
|
-
});
|
|
1154
|
-
server.listen(0, "127.0.0.1");
|
|
1155
|
-
await once(server, "listening");
|
|
1156
|
-
const address = server.address();
|
|
1157
|
-
if (!address || typeof address === "string") {
|
|
1158
|
-
throw new Error("test server did not bind a TCP port");
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
try {
|
|
1162
|
-
const io = new PresignObjectIO(
|
|
1163
|
-
streamingVault(`http://127.0.0.1:${address.port}`),
|
|
1164
|
-
COMPANY,
|
|
1165
|
-
);
|
|
1166
|
-
const streamed = await io.getObjectStream("large");
|
|
1167
|
-
const iterator = streamed.body[Symbol.asyncIterator]();
|
|
1168
|
-
expect((await iterator.next()).value).toBeInstanceOf(Uint8Array);
|
|
1169
|
-
await iterator.return?.();
|
|
1170
|
-
if (!responseClosed) throw new Error("response did not start streaming");
|
|
1171
|
-
await expect(responseClosed).resolves.toBeDefined();
|
|
1172
|
-
|
|
1173
|
-
await expect(io.getObject("short")).rejects.toThrow(
|
|
1174
|
-
/content-length mismatch/,
|
|
1175
|
-
);
|
|
1176
|
-
} finally {
|
|
1177
|
-
server.close();
|
|
1178
|
-
await once(server, "close");
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1181
|
-
|
|
1182
|
-
it.runIf(
|
|
1183
|
-
process.platform === "win32" && /^(22|24)\./.test(process.versions.node),
|
|
1184
|
-
)("keeps a child FIN safe after the consumer has applied backpressure", async () => {
|
|
1185
|
-
setPresignedGetTransportForTesting(null);
|
|
1186
|
-
const child = spawn(process.execPath, [
|
|
1187
|
-
"-e",
|
|
1188
|
-
[
|
|
1189
|
-
"const http = require('node:http');",
|
|
1190
|
-
"const body = Buffer.alloc(524288, 7);",
|
|
1191
|
-
"const server = http.createServer((_req, res) => {",
|
|
1192
|
-
" res.writeHead(200, { 'content-length': String(body.length) });",
|
|
1193
|
-
" for (let offset = 0; offset < body.length; offset += 16384) res.write(body.subarray(offset, offset + 16384));",
|
|
1194
|
-
" res.end();",
|
|
1195
|
-
"});",
|
|
1196
|
-
"server.listen(0, '127.0.0.1', () => process.stdout.write(String(server.address().port) + '\\n'));",
|
|
1197
|
-
"process.on('SIGTERM', () => server.close(() => process.exit(0)));",
|
|
1198
|
-
].join("\n"),
|
|
1199
|
-
], { stdio: ["ignore", "pipe", "inherit"] });
|
|
1200
|
-
|
|
1201
|
-
const port = await new Promise<number>((resolve, reject) => {
|
|
1202
|
-
child.once("error", reject);
|
|
1203
|
-
child.stdout?.once("data", (data: Buffer) => resolve(Number(data.toString())));
|
|
1204
|
-
child.once("exit", (code) => reject(new Error(`child server exited (${code})`)));
|
|
1205
|
-
});
|
|
1206
|
-
|
|
1207
|
-
try {
|
|
1208
|
-
const io = new PresignObjectIO(
|
|
1209
|
-
streamingVault(`http://127.0.0.1:${port}`),
|
|
1210
|
-
COMPANY,
|
|
1211
|
-
);
|
|
1212
|
-
const streamed = await io.getObjectStream("bulk");
|
|
1213
|
-
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
1214
|
-
let bytes = 0;
|
|
1215
|
-
for await (const chunk of streamed.body) bytes += chunk.byteLength;
|
|
1216
|
-
expect(bytes).toBe(524_288);
|
|
1217
|
-
} finally {
|
|
1218
|
-
child.kill("SIGTERM");
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1221
|
-
});
|