@indigoai-us/hq-cloud 6.16.76-alpha.0 → 6.16.78-alpha.0

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.
@@ -68,7 +68,7 @@ import { share, ServerOwnedPushPathsError, UnreachablePushPathsError, Unregister
68
68
  import { deleteRemoteFile, downloadFile, headRemoteFile, primeObjectTransport, primeUploads, uploadFile, uploadSymlink, WindowsSymlinkPrivilegeError, } from "../s3.js";
69
69
  import { VaultAuthError, VaultClientError, VaultConflictError, VaultPermissionDeniedError, } from "../vault-client.js";
70
70
  import { CognitoRefreshError } from "../cognito-auth.js";
71
- import { RateLimitedError } from "../object-io.js";
71
+ import { ObjectLockChecksumRequiredError, RateLimitedError, } from "../object-io.js";
72
72
  import { AreaLedgerMigration, closeCachedAreaJournalMigration, hashFile, openJournalStateStoreForMigration, readJournal, readJournalScoped, setAreaLedgerMigrationTestHooksForTest, writeJournal, } from "../journal.js";
73
73
  import { ReconcileCursorStore } from "../sync/reconcile-cursor.js";
74
74
  import { AreaResolver } from "../sync/area-resolver.js";
@@ -2019,6 +2019,109 @@ describe("share", () => {
2019
2019
  vi.mocked(uploadFile).mockResolvedValue({ etag: '"upload-etag"' });
2020
2020
  }
2021
2021
  });
2022
+ it.each([
2023
+ [
2024
+ "429 throttle",
2025
+ () => new RateLimitedError("test.md", "put"),
2026
+ "RateLimited",
2027
+ true,
2028
+ ],
2029
+ [
2030
+ "503 throttle",
2031
+ () => Object.assign(new Error("presign request failed (503)"), {
2032
+ statusCode: 503,
2033
+ }),
2034
+ "503",
2035
+ true,
2036
+ ],
2037
+ [
2038
+ "Object Lock 400 checksum refusal",
2039
+ () => new ObjectLockChecksumRequiredError("test.md", "checksum required"),
2040
+ "ObjectLockChecksumRequired",
2041
+ false,
2042
+ ],
2043
+ [
2044
+ "request timeout",
2045
+ () => Object.assign(new Error("request timed out"), { name: "TimeoutError" }),
2046
+ "TimeoutError",
2047
+ true,
2048
+ ],
2049
+ [
2050
+ "caller abort",
2051
+ () => Object.assign(new Error("request aborted"), { name: "AbortError" }),
2052
+ "AbortError",
2053
+ true,
2054
+ ],
2055
+ [
2056
+ "nested transport failure",
2057
+ () => Object.assign(new TypeError("fetch failed"), {
2058
+ cause: Object.assign(new Error("socket reset"), { code: "ECONNRESET" }),
2059
+ }),
2060
+ "fetch failed",
2061
+ true,
2062
+ ],
2063
+ ])("remote failure contract classifies %s, preserves its journal row, and emits its reason", async (_description, makeFailure, telemetryReason, deferred) => {
2064
+ const companyRoot = path.join(tmpDir, "companies", "acme");
2065
+ fs.mkdirSync(companyRoot, { recursive: true });
2066
+ const testFile = path.join(companyRoot, "test.md");
2067
+ fs.writeFileSync(testFile, "# Hello World");
2068
+ const journalPath = path.join(stateDir, "sync-journal.acme.json");
2069
+ const staleHash = "stale-hash-for-old-content";
2070
+ seedJournalAt(journalPath, {
2071
+ version: "1",
2072
+ lastSync: new Date(Date.now() - 60_000).toISOString(),
2073
+ files: {
2074
+ "test.md": {
2075
+ hash: staleHash,
2076
+ size: 5,
2077
+ syncedAt: new Date(Date.now() - 60_000).toISOString(),
2078
+ direction: "up",
2079
+ remoteEtag: "old-etag",
2080
+ },
2081
+ },
2082
+ });
2083
+ vi.mocked(uploadFile).mockReset();
2084
+ vi.mocked(uploadFile).mockRejectedValueOnce(makeFailure());
2085
+ try {
2086
+ const events = [];
2087
+ const result = await share({
2088
+ paths: [testFile],
2089
+ company: "acme",
2090
+ vaultConfig: mockConfig,
2091
+ hqRoot: tmpDir,
2092
+ onEvent: (event) => events.push(event),
2093
+ });
2094
+ expect(result.filesUploaded).toBe(0);
2095
+ expect(journalAt(journalPath).files["test.md"]).toMatchObject({
2096
+ hash: staleHash,
2097
+ remoteEtag: "old-etag",
2098
+ });
2099
+ expect(events).toContainEqual(expect.objectContaining({
2100
+ type: "error",
2101
+ path: "test.md",
2102
+ message: expect.stringContaining(telemetryReason),
2103
+ }));
2104
+ if (deferred) {
2105
+ expect(result.filesSkipped).toBeGreaterThanOrEqual(1);
2106
+ expect(events).toContainEqual(expect.objectContaining({
2107
+ type: "error",
2108
+ diagnostic: true,
2109
+ path: "test.md",
2110
+ }));
2111
+ expect(events.some((event) => event.type === "error" && event.diagnostic !== true)).toBe(false);
2112
+ }
2113
+ else {
2114
+ expect(result.filesSkipped).toBe(0);
2115
+ const errorEvent = events.find((event) => event.type === "error");
2116
+ expect(errorEvent).toMatchObject({ type: "error", path: "test.md" });
2117
+ expect(errorEvent).not.toHaveProperty("diagnostic");
2118
+ }
2119
+ }
2120
+ finally {
2121
+ vi.mocked(uploadFile).mockReset();
2122
+ vi.mocked(uploadFile).mockResolvedValue({ etag: '"upload-etag"' });
2123
+ }
2124
+ });
2022
2125
  it("still emits a hard error when upload throws a generic Error", async () => {
2023
2126
  const companyRoot = path.join(tmpDir, "companies", "acme");
2024
2127
  fs.mkdirSync(companyRoot, { recursive: true });
@@ -3908,6 +4011,54 @@ describe("share", () => {
3908
4011
  expect(calls[0][4]).toEqual({ ifNoneMatch: "*" });
3909
4012
  expect(calls[1][4]).toBeUndefined();
3910
4013
  });
4014
+ it("defers a retryable upload failure after overwrite conflict resolution", async () => {
4015
+ const companyRoot = path.join(tmpDir, "companies", "acme");
4016
+ fs.mkdirSync(companyRoot, { recursive: true });
4017
+ const testFile = path.join(companyRoot, "retry-later.md");
4018
+ fs.writeFileSync(testFile, "keep journaled until the next pass");
4019
+ const journalPath = path.join(stateDir, "sync-journal.acme.json");
4020
+ const staleHash = "old-retry-later-hash";
4021
+ seedJournalAt(journalPath, {
4022
+ version: "1",
4023
+ lastSync: new Date(Date.now() - 60_000).toISOString(),
4024
+ files: {
4025
+ "retry-later.md": {
4026
+ hash: staleHash,
4027
+ size: 5,
4028
+ syncedAt: new Date(Date.now() - 60_000).toISOString(),
4029
+ direction: "up",
4030
+ remoteEtag: "old-etag",
4031
+ },
4032
+ },
4033
+ });
4034
+ vi.mocked(headRemoteFile).mockResolvedValueOnce(null);
4035
+ vi.mocked(uploadFile)
4036
+ .mockRejectedValueOnce(fence412())
4037
+ .mockRejectedValueOnce(Object.assign(new Error("retry PUT timed out"), { name: "TimeoutError" }));
4038
+ const events = [];
4039
+ const result = await share({
4040
+ paths: [testFile],
4041
+ company: "acme",
4042
+ vaultConfig: mockConfig,
4043
+ hqRoot: tmpDir,
4044
+ onConflict: "overwrite",
4045
+ onEvent: (event) => events.push(event),
4046
+ });
4047
+ expect(vi.mocked(uploadFile)).toHaveBeenCalledTimes(2);
4048
+ expect(result.filesUploaded).toBe(0);
4049
+ expect(result.filesSkipped).toBe(1);
4050
+ expect(journalAt(journalPath).files["retry-later.md"]).toMatchObject({
4051
+ hash: staleHash,
4052
+ remoteEtag: "old-etag",
4053
+ });
4054
+ expect(events).toContainEqual(expect.objectContaining({
4055
+ type: "error",
4056
+ diagnostic: true,
4057
+ path: "retry-later.md",
4058
+ message: expect.stringContaining("TimeoutError"),
4059
+ }));
4060
+ expect(events.some((event) => event.type === "error" && event.diagnostic !== true)).toBe(false);
4061
+ });
3911
4062
  it("412 under abort: halts the pass", async () => {
3912
4063
  const companyRoot = path.join(tmpDir, "companies", "acme");
3913
4064
  fs.mkdirSync(companyRoot, { recursive: true });