cursedbelt-server 4.48.0 → 4.49.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.
- package/dist/server/activity/store.d.ts +1 -1
- package/dist/server/analytics/injectedScripts.d.ts +1 -1
- package/dist/server/analytics/injectedScripts.js +1 -1
- package/dist/server/analytics/webAnalytics.d.ts +1 -1
- package/dist/server/analytics/webAnalytics.js +1 -1
- package/dist/server/auth/loginThrottleDurable.d.ts +3 -3
- package/dist/server/auth/loginThrottleDurable.js +3 -3
- package/dist/server/auth/passwordCost.js +1 -1
- package/dist/server/ctgrChunkDurable.d.ts +1 -1
- package/dist/server/ctgrChunkDurable.js +1 -1
- package/dist/server/d1/backup.d.ts +1 -1
- package/dist/server/d1/backup.js +1 -1
- package/dist/server/d1/http.d.ts +2 -2
- package/dist/server/d1/http.js +2 -2
- package/dist/server/d1/invocation.js +1 -1
- package/dist/server/d1/limits.d.ts +1 -1
- package/dist/server/d1/limits.js +1 -1
- package/dist/server/d1/pullD1.d.ts +4 -1
- package/dist/server/d1/pullD1.js +5 -2
- package/dist/server/d1/scheduling.d.ts +1 -1
- package/dist/server/d1/scheduling.js +1 -1
- package/dist/server/d1/types.d.ts +1 -1
- package/dist/server/d1/types.js +1 -1
- package/dist/server/d1/values.d.ts +1 -1
- package/dist/server/d1/values.js +1 -1
- package/dist/server/dropzone/index.d.ts +1 -0
- package/dist/server/dropzone/index.js +1 -0
- package/dist/server/dropzone/report.d.ts +188 -0
- package/dist/server/dropzone/report.js +430 -0
- package/dist/server/dropzone/scan.d.ts +22 -3
- package/dist/server/dropzone/scan.js +46 -1
- package/dist/server/engagement/index.d.ts +1 -1
- package/dist/server/engagement/index.js +1 -1
- package/dist/server/guard/argon2Binding.js +1 -1
- package/dist/server/guard/kdfWorkerEntry.js +2 -2
- package/dist/server/incidents/index.d.ts +1 -1
- package/dist/server/incidents/index.js +1 -1
- package/dist/server/incidents/store.d.ts +1 -1
- package/dist/server/incidents/store.js +1 -1
- package/dist/server/jobs/timeout.d.ts +1 -1
- package/dist/server/jobs/timeout.js +1 -1
- package/dist/server/master-lock/accountsPage.d.ts +1 -1
- package/dist/server/master-lock/accountsPage.js +2 -2
- package/dist/server/master-lock/guard.js +1 -1
- package/dist/server/master-lock/lockPage.d.ts +1 -1
- package/dist/server/master-lock/lockPage.js +2 -2
- package/dist/server/master-lock/masterLock.d.ts +2 -2
- package/dist/server/master-lock/masterLock.js +2 -2
- package/dist/server/metrics/normalizeRoute.js +1 -1
- package/dist/server/metrics/telemetrySink.d.ts +2 -2
- package/dist/server/metrics/telemetrySink.js +1 -1
- package/dist/server/middleware/zValidator.js +2 -2
- package/dist/server/notifications/hub.js +1 -1
- package/dist/server/requestLog/requestMetrics.d.ts +2 -2
- package/dist/server/requestLog/requestMetrics.js +2 -2
- package/dist/server/retention/archive.d.ts +1 -1
- package/dist/server/retention/archive.js +2 -2
- package/dist/server/satellite/config.js +2 -2
- package/dist/server/satellite/door.d.ts +1 -1
- package/dist/server/sharing/contract.d.ts +1 -1
- package/dist/server/storage/binaryStore.d.ts +1 -1
- package/dist/server/storage/binaryStore.js +3 -3
- package/dist/server/storage/derivatives.d.ts +2 -2
- package/dist/server/storage/derivatives.js +2 -2
- package/dist/server/storage/files/adapter.d.ts +2 -2
- package/dist/server/storage/files/adapter.js +10 -10
- package/dist/server/storage/files/catalogue.d.ts +1 -1
- package/dist/server/storage/files/catalogue.js +4 -4
- package/dist/server/storage/files/chunkedUpload.d.ts +2 -2
- package/dist/server/storage/files/chunkedUpload.js +1 -1
- package/dist/server/storage/files/fileRoutes.d.ts +1 -1
- package/dist/server/storage/files/fileRoutes.js +4 -4
- package/dist/server/storage/files/mimeByExt.js +1 -1
- package/dist/server/storage/files/stack.d.ts +2 -2
- package/dist/server/storage/files/types.d.ts +4 -4
- package/dist/server/storage/files/types.js +1 -1
- package/dist/server/storage/index.js +1 -1
- package/dist/server/storage/objectStoreMediaStore.js +1 -1
- package/dist/server/storage/transcodeJobs.js +5 -5
- package/dist/server/storage/types.d.ts +1 -1
- package/dist/server/storage/types.js +1 -1
- package/dist/server/storage/videoDerivativeKeys.d.ts +1 -1
- package/dist/server/storage/videoDerivativeKeys.js +1 -1
- package/dist/server/storage/videoProcessor.js +1 -1
- package/dist/server/sync/status.d.ts +1 -1
- package/dist/server/zipStream.d.ts +1 -1
- package/dist/server/zipStream.js +1 -1
- package/docs/activity.md +2 -2
- package/docs/retention.md +2 -2
- package/package.json +1 -1
- package/src/leafSubpathsImportNothing.spec.ts +1 -1
- package/src/namedSubpathsResolve.spec.ts +1 -1
- package/src/noTimerDialsAPeer.spec.ts +1 -1
- package/src/nodeBuiltinsAreProbedByCalling.spec.ts +1 -1
- package/src/publishShape.spec.ts +1 -1
- package/src/server/activity/store.ts +1 -1
- package/src/server/analytics/injectedScripts.spec.ts +1 -1
- package/src/server/analytics/injectedScripts.ts +1 -1
- package/src/server/analytics/webAnalytics.ts +1 -1
- package/src/server/auth/loginThrottleDurable.ts +3 -3
- package/src/server/auth/passwordCost.ts +1 -1
- package/src/server/bench/cpuBudget.spec.ts +1 -1
- package/src/server/bench/tail.spec.ts +1 -1
- package/src/server/ctgrChunkDurable.ts +1 -1
- package/src/server/d1/backup.spec.ts +1 -1
- package/src/server/d1/backup.ts +1 -1
- package/src/server/d1/http.ts +2 -2
- package/src/server/d1/invocation.spec.ts +1 -1
- package/src/server/d1/invocation.ts +1 -1
- package/src/server/d1/limits.ts +1 -1
- package/src/server/d1/pullD1.spec.ts +9 -1
- package/src/server/d1/pullD1.ts +5 -2
- package/src/server/d1/scheduling.ts +1 -1
- package/src/server/d1/types.ts +1 -1
- package/src/server/d1/values.ts +1 -1
- package/src/server/dropzone/index.ts +8 -0
- package/src/server/dropzone/report.spec.ts +275 -0
- package/src/server/dropzone/report.ts +568 -0
- package/src/server/dropzone/scan.spec.ts +2 -2
- package/src/server/dropzone/scan.ts +68 -5
- package/src/server/engagement/engagement.spec.ts +1 -1
- package/src/server/engagement/index.ts +1 -1
- package/src/server/google-oauth/googleOAuth.spec.ts +1 -1
- package/src/server/guard/argon2Binding.ts +1 -1
- package/src/server/guard/kdfWorkerEntry.ts +2 -2
- package/src/server/incidents/index.ts +1 -1
- package/src/server/incidents/store.ts +1 -1
- package/src/server/jobs/timeout.ts +1 -1
- package/src/server/master-lock/accountsPage.spec.ts +2 -2
- package/src/server/master-lock/accountsPage.ts +2 -2
- package/src/server/master-lock/beaconNeverReachesTheWall.spec.ts +2 -2
- package/src/server/master-lock/guard.spec.ts +2 -2
- package/src/server/master-lock/guard.ts +1 -1
- package/src/server/master-lock/lockPage.spec.ts +1 -1
- package/src/server/master-lock/lockPage.ts +2 -2
- package/src/server/master-lock/masterLock.spec.ts +1 -1
- package/src/server/master-lock/masterLock.ts +2 -2
- package/src/server/master-lock/sessions.spec.ts +1 -1
- package/src/server/metrics/normalizeRoute.ts +1 -1
- package/src/server/metrics/telemetrySink.ts +3 -3
- package/src/server/middleware/bodyLimit.spec.ts +1 -1
- package/src/server/middleware/zValidator.spec.ts +3 -3
- package/src/server/middleware/zValidator.ts +3 -3
- package/src/server/notifications/hub.ts +1 -1
- package/src/server/requestLog/requestMetrics.spec.ts +2 -2
- package/src/server/requestLog/requestMetrics.ts +3 -3
- package/src/server/retention/archive.spec.ts +2 -2
- package/src/server/retention/archive.ts +2 -2
- package/src/server/satellite/config.ts +2 -2
- package/src/server/satellite/door.ts +1 -1
- package/src/server/satellite/satellite.spec.ts +1 -1
- package/src/server/sharing/contract.ts +1 -1
- package/src/server/storage/binaryServerProcessing.spec.ts +1 -1
- package/src/server/storage/binaryServerProcessing.ts +4 -4
- package/src/server/storage/binaryStore.spec.ts +6 -6
- package/src/server/storage/binaryStore.ts +4 -4
- package/src/server/storage/chunked.integration.spec.ts +2 -2
- package/src/server/storage/derivatives.ts +2 -2
- package/src/server/storage/fileUploadClient.integration.spec.ts +1 -1
- package/src/server/storage/files/adapter.photo.spec.ts +2 -2
- package/src/server/storage/files/adapter.spec.ts +3 -3
- package/src/server/storage/files/adapter.ts +10 -10
- package/src/server/storage/files/catalogue.spec.ts +1 -1
- package/src/server/storage/files/catalogue.ts +4 -4
- package/src/server/storage/files/chunkedUpload.spec.ts +5 -5
- package/src/server/storage/files/chunkedUpload.ts +3 -3
- package/src/server/storage/files/fileRoutes.spec.ts +3 -3
- package/src/server/storage/files/fileRoutes.ts +5 -5
- package/src/server/storage/files/mimeByExt.ts +1 -1
- package/src/server/storage/files/stack.ts +3 -3
- package/src/server/storage/files/types.ts +6 -6
- package/src/server/storage/index.ts +1 -1
- package/src/server/storage/objectStoreMediaStore.ts +1 -1
- package/src/server/storage/sources.ts +1 -1
- package/src/server/storage/transcodeJobs.ts +5 -5
- package/src/server/storage/types.ts +2 -2
- package/src/server/storage/uploadSession.spec.ts +1 -1
- package/src/server/storage/videoDerivativeKeys.spec.ts +3 -3
- package/src/server/storage/videoDerivativeKeys.ts +1 -1
- package/src/server/storage/videoProcessor.ts +1 -1
- package/src/server/sync/status.ts +1 -1
- package/src/server/sync/timer.spec.ts +1 -1
- package/src/server/worker-argon2/index.spec.ts +1 -1
- package/src/server/zipStream.spec.ts +2 -2
- package/src/server/zipStream.ts +1 -1
- package/src/shippedFilesAreTracked.spec.ts +2 -2
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
createIngestReporter,
|
|
7
|
+
FILES_JOURNAL,
|
|
8
|
+
LOOSE_FILES,
|
|
9
|
+
PROGRESS_FILE,
|
|
10
|
+
QUEUE_FILE,
|
|
11
|
+
sourceIdOf,
|
|
12
|
+
type FileLine,
|
|
13
|
+
type IngestProgress,
|
|
14
|
+
type QueueLine,
|
|
15
|
+
type ReportFile,
|
|
16
|
+
type ReporterOptions,
|
|
17
|
+
} from "./report.js";
|
|
18
|
+
import { sweepDropzone } from "./scan.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What a sweep writes for station's Uploads page (`report.ts`, forge task 3588). Each test plays one
|
|
22
|
+
* or two sweeps through the reporter's hooks the way a sweep calls them — collections' own, or
|
|
23
|
+
* `sweepDropzone`'s, which family and music run.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
let root: string;
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
root = mkdtempSync(join(tmpdir(), "dropzone-report-spec-"));
|
|
29
|
+
});
|
|
30
|
+
afterEach(() => rmSync(root, { recursive: true, force: true }));
|
|
31
|
+
|
|
32
|
+
const ACCOUNT = "acct-1";
|
|
33
|
+
|
|
34
|
+
function world() {
|
|
35
|
+
const stateDir = join(root, "state");
|
|
36
|
+
const accountDir = join(root, "dropzone", "2026-09-10 Account 1");
|
|
37
|
+
mkdirSync(accountDir, { recursive: true });
|
|
38
|
+
let clock = Date.parse("2026-10-22T12:00:00Z");
|
|
39
|
+
const reporter = (extra: Partial<ReporterOptions> = {}) =>
|
|
40
|
+
createIngestReporter({
|
|
41
|
+
stateDir,
|
|
42
|
+
app: "collections",
|
|
43
|
+
job: "com.collections.ingest",
|
|
44
|
+
everySeconds: 300,
|
|
45
|
+
dropzone: join(root, "dropzone"),
|
|
46
|
+
accounts: [{ id: ACCOUNT, label: "Account 1", dir: accountDir }],
|
|
47
|
+
now: () => clock,
|
|
48
|
+
pid: 1,
|
|
49
|
+
...extra,
|
|
50
|
+
});
|
|
51
|
+
const file = (relativePath: string, size: number): ReportFile => ({ path: join(accountDir, relativePath), relativePath, size, accountId: ACCOUNT });
|
|
52
|
+
const progress = (): IngestProgress => JSON.parse(readFileSync(join(stateDir, PROGRESS_FILE), "utf8")) as IngestProgress;
|
|
53
|
+
const lines = <T>(name: string): T[] =>
|
|
54
|
+
readFileSync(join(stateDir, name), "utf8")
|
|
55
|
+
.split("\n")
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.map((l) => JSON.parse(l) as T);
|
|
58
|
+
return { stateDir, accountDir, reporter, file, progress, lines, tick: (ms: number) => (clock += ms) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("sources", () => {
|
|
62
|
+
test("each top-level folder or link is one source, and loose files are one more", () => {
|
|
63
|
+
expect(sourceIdOf(ACCOUNT, "tod/a/b.mp4")).toEqual({ id: `${ACCOUNT}:tod`, label: "tod", top: "tod" });
|
|
64
|
+
expect(sourceIdOf(ACCOUNT, "photo.jpg")).toEqual({ id: `${ACCOUNT}:`, label: LOOSE_FILES, top: null });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("a linked folder over one sweep", () => {
|
|
69
|
+
test("settled, uploading, filed and waiting files each land in their tally, the queue and the journal", () => {
|
|
70
|
+
const w = world();
|
|
71
|
+
symlinkSync("/Volumes/databundle/tod", join(w.accountDir, "tod"));
|
|
72
|
+
const settled = w.file("tod/old.mp4", 100);
|
|
73
|
+
const going = w.file("tod/new.mp4", 200);
|
|
74
|
+
const waiting = w.file("tod/big.mp4", 5_000);
|
|
75
|
+
|
|
76
|
+
const r = w.reporter({ driveOf: (target) => ({ volume: "/Volumes/databundle", state: target.startsWith("/Volumes/databundle") ? "ok" : "deleted" }) });
|
|
77
|
+
r.walking();
|
|
78
|
+
r.found([settled, going, waiting], (f) => (f === settled ? { outcome: "added", at: "2026-10-21T09:00:00.000Z" } : undefined));
|
|
79
|
+
r.progress.waiting(settled, "done");
|
|
80
|
+
r.progress.waiting(waiting, "room");
|
|
81
|
+
r.progress.uploading(going, "file/u_abc");
|
|
82
|
+
|
|
83
|
+
const mid = w.progress().sources[0];
|
|
84
|
+
expect(mid).toMatchObject({ label: "tod", kind: "linked", target: "/Volumes/databundle/tod", drive: { volume: "/Volumes/databundle", state: "ok" }, startedAt: "2026-10-21T09:00:00.000Z", finishedAt: null });
|
|
85
|
+
expect(mid?.current).toMatchObject({ path: "tod/new.mp4", key: "file/u_abc", bytes: 200 });
|
|
86
|
+
expect(mid?.total).toEqual({ files: 3, bytes: 5_300 });
|
|
87
|
+
expect(mid?.done).toEqual({ files: 1, bytes: 100 });
|
|
88
|
+
|
|
89
|
+
w.tick(60_000);
|
|
90
|
+
r.result(going, { outcome: "added", itemId: "item-1" });
|
|
91
|
+
r.finish();
|
|
92
|
+
|
|
93
|
+
const end = w.progress();
|
|
94
|
+
expect(end.sweep).toMatchObject({ state: "finished", phase: "done" });
|
|
95
|
+
expect(end.sources[0]).toMatchObject({ added: 1, current: null, finishedAt: null, done: { files: 2, bytes: 300 }, waitingForRoom: { files: 1, bytes: 5_000 } });
|
|
96
|
+
expect(w.lines<QueueLine>(QUEUE_FILE)).toEqual([{ source: `${ACCOUNT}:tod`, path: "tod/big.mp4", bytes: 5_000, state: "waiting-room" }]);
|
|
97
|
+
// The settled file is the journal's first line, at its own date; the sweep's follows.
|
|
98
|
+
expect(w.lines<FileLine>(FILES_JOURNAL).map((l) => [l.path, l.outcome, Boolean(l.backfilled)])).toEqual([
|
|
99
|
+
["tod/old.mp4", "added", true],
|
|
100
|
+
["tod/new.mp4", "added", false],
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a drive that is not plugged in keeps the source's last totals, all waiting for the drive", () => {
|
|
105
|
+
const w = world();
|
|
106
|
+
symlinkSync("/Volumes/databundle/tod", join(w.accountDir, "tod"));
|
|
107
|
+
const a = w.file("tod/a.mp4", 100);
|
|
108
|
+
const b = w.file("tod/b.mp4", 300);
|
|
109
|
+
const first = w.reporter();
|
|
110
|
+
first.found([a, b]);
|
|
111
|
+
first.result(a, { outcome: "added", itemId: "i" });
|
|
112
|
+
first.finish();
|
|
113
|
+
|
|
114
|
+
const second = w.reporter({ driveOf: () => ({ volume: "/Volumes/databundle", state: "unmounted" }) });
|
|
115
|
+
second.walking();
|
|
116
|
+
second.unreachable(ACCOUNT, "tod", "/Volumes/databundle/tod");
|
|
117
|
+
second.found([]);
|
|
118
|
+
second.finish();
|
|
119
|
+
|
|
120
|
+
expect(w.progress().sources.find((s) => s.label === "tod")).toMatchObject({
|
|
121
|
+
total: { files: 2, bytes: 400 },
|
|
122
|
+
done: { files: 1, bytes: 100 },
|
|
123
|
+
waitingForDrive: { files: 1, bytes: 300 },
|
|
124
|
+
drive: { state: "unmounted" },
|
|
125
|
+
finishedAt: null,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("🔴 a driveOf or room that throws costs the page a field, never the sweep a file", () => {
|
|
130
|
+
const w = world();
|
|
131
|
+
symlinkSync("/Volumes/databundle/tod", join(w.accountDir, "tod"));
|
|
132
|
+
const warned: string[] = [];
|
|
133
|
+
const r = w.reporter({
|
|
134
|
+
driveOf: () => {
|
|
135
|
+
throw new Error("statfs EIO");
|
|
136
|
+
},
|
|
137
|
+
room: () => {
|
|
138
|
+
throw new Error("statfs EIO");
|
|
139
|
+
},
|
|
140
|
+
warn: (line) => warned.push(line),
|
|
141
|
+
});
|
|
142
|
+
expect(() => r.found([w.file("tod/a.mp4", 1)])).not.toThrow();
|
|
143
|
+
expect(() => r.finish()).not.toThrow();
|
|
144
|
+
expect(warned).toHaveLength(1);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("a dropped folder empties as it is filed", () => {
|
|
149
|
+
test("🔴 what an earlier sweep filed is carried, so the run's total does not shrink as the folder does", () => {
|
|
150
|
+
const w = world();
|
|
151
|
+
const one = w.file("Vacation/1.jpg", 10);
|
|
152
|
+
const two = w.file("Vacation/2.jpg", 20);
|
|
153
|
+
const first = w.reporter();
|
|
154
|
+
first.found([one, two]);
|
|
155
|
+
first.result(one, { outcome: "added", itemId: "i1" });
|
|
156
|
+
first.progress.waiting(two, "copying");
|
|
157
|
+
first.finish();
|
|
158
|
+
const startedAt = w.progress().sources[0]?.startedAt;
|
|
159
|
+
|
|
160
|
+
w.tick(300_000);
|
|
161
|
+
const second = w.reporter();
|
|
162
|
+
second.found([two]);
|
|
163
|
+
second.result(two, { outcome: "duplicate", itemId: "i0" });
|
|
164
|
+
second.finish();
|
|
165
|
+
|
|
166
|
+
const run = w.progress().sources[0];
|
|
167
|
+
expect(run).toMatchObject({ label: "Vacation", kind: "folder", startedAt, added: 1, duplicate: 1, total: { files: 2, bytes: 30 }, done: { files: 2, bytes: 30 } });
|
|
168
|
+
expect(run?.finishedAt).toBe("2026-10-22T12:05:00.000Z");
|
|
169
|
+
|
|
170
|
+
w.tick(300_000);
|
|
171
|
+
const third = w.reporter();
|
|
172
|
+
third.found([]);
|
|
173
|
+
third.finish();
|
|
174
|
+
expect(w.progress().sources[0]).toMatchObject({ label: "Vacation", finishedAt: "2026-10-22T12:05:00.000Z", total: { files: 2, bytes: 30 } });
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a failed file is counted as failed, and the queue keeps it with its state", () => {
|
|
178
|
+
const w = world();
|
|
179
|
+
const bad = w.file("broken.mov", 7);
|
|
180
|
+
const r = w.reporter();
|
|
181
|
+
r.found([bad]);
|
|
182
|
+
r.progress.uploading(bad, "file/u_1");
|
|
183
|
+
r.result(bad, { outcome: "failed", detail: "500 boom" });
|
|
184
|
+
r.finish();
|
|
185
|
+
expect(w.progress().sources[0]).toMatchObject({ label: LOOSE_FILES, failed: { files: 1, bytes: 7 }, done: { files: 0, bytes: 0 } });
|
|
186
|
+
expect(w.lines<QueueLine>(QUEUE_FILE)[0]).toMatchObject({ path: "broken.mov", state: "failed" });
|
|
187
|
+
expect(w.lines<FileLine>(FILES_JOURNAL)[0]).toMatchObject({ outcome: "failed", detail: "500 boom" });
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("a sweep that stopped on an error says so, and keeps every source as it was", () => {
|
|
191
|
+
const w = world();
|
|
192
|
+
const r1 = w.reporter();
|
|
193
|
+
r1.found([w.file("x.jpg", 1)]);
|
|
194
|
+
r1.finish();
|
|
195
|
+
const r2 = w.reporter();
|
|
196
|
+
r2.finish("accounts route answered 500");
|
|
197
|
+
const p = w.progress();
|
|
198
|
+
expect(p.sweep).toMatchObject({ state: "failed", error: "accounts route answered 500" });
|
|
199
|
+
expect(p.sources).toHaveLength(1);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe("sweepDropzone writes the report by itself (family's and music's sweeps)", () => {
|
|
204
|
+
const dropzone = () => join(root, "drop");
|
|
205
|
+
const put = (rel: string, bytes = 8): void => {
|
|
206
|
+
const full = join(dropzone(), rel);
|
|
207
|
+
mkdirSync(join(full, ".."), { recursive: true });
|
|
208
|
+
writeFileSync(full, Buffer.alloc(bytes, 7));
|
|
209
|
+
};
|
|
210
|
+
const reporter = () =>
|
|
211
|
+
createIngestReporter({
|
|
212
|
+
stateDir: join(root, "state"),
|
|
213
|
+
app: "family",
|
|
214
|
+
job: "com.family.ingest",
|
|
215
|
+
everySeconds: 300,
|
|
216
|
+
dropzone: dropzone(),
|
|
217
|
+
accounts: [{ id: "", label: "Family drop folder", dir: dropzone() }],
|
|
218
|
+
pid: 1,
|
|
219
|
+
});
|
|
220
|
+
const progress = (): IngestProgress => JSON.parse(readFileSync(join(root, "state", PROGRESS_FILE), "utf8")) as IngestProgress;
|
|
221
|
+
const journal = (): FileLine[] =>
|
|
222
|
+
readFileSync(join(root, "state", FILES_JOURNAL), "utf8")
|
|
223
|
+
.split("\n")
|
|
224
|
+
.filter(Boolean)
|
|
225
|
+
.map((l) => JSON.parse(l) as FileLine);
|
|
226
|
+
|
|
227
|
+
test("each album folder is a source, every outcome is journaled in the page's words, and the sweep's end is recorded", async () => {
|
|
228
|
+
put("Wedding 1998/a.jpg", 10);
|
|
229
|
+
put("Wedding 1998/b.jpg", 20);
|
|
230
|
+
put("Wedding 1998/notes.xyz", 3);
|
|
231
|
+
put("loose.jpg", 5);
|
|
232
|
+
put("maybe.jpg", 4);
|
|
233
|
+
const keys: string[] = [];
|
|
234
|
+
await sweepDropzone(
|
|
235
|
+
dropzone(),
|
|
236
|
+
async (file, ctx) => {
|
|
237
|
+
if (file.name === "notes.xyz") return { kind: "discard", detail: "not a photograph" };
|
|
238
|
+
if (file.name === "b.jpg") return { kind: "duplicate" };
|
|
239
|
+
if (file.name === "loose.jpg") return { kind: "failed", detail: "502 from prod" };
|
|
240
|
+
if (file.name === "maybe.jpg") return { kind: "held", detail: "looks like real/media/x" };
|
|
241
|
+
ctx.uploading(`real/media/${file.name}`);
|
|
242
|
+
keys.push(progress().sources.find((s) => s.current)?.current?.key ?? "");
|
|
243
|
+
return { kind: "stored" };
|
|
244
|
+
},
|
|
245
|
+
{ stabilityMs: 0, report: reporter() },
|
|
246
|
+
);
|
|
247
|
+
// The handler named its key while the file was going in — the page's live line for that file.
|
|
248
|
+
expect(keys).toEqual(["real/media/a.jpg"]);
|
|
249
|
+
const p = progress();
|
|
250
|
+
expect(p.sweep).toMatchObject({ state: "finished", phase: "done" });
|
|
251
|
+
expect(p.sources.find((s) => s.label === "Wedding 1998")).toMatchObject({ kind: "folder", added: 1, duplicate: 1, blocked: 1, total: { files: 3, bytes: 33 } });
|
|
252
|
+
// A held file is left alone, not an event: it is shown as skipped and never journaled, so the
|
|
253
|
+
// sweep that meets it again in five minutes does not write it again.
|
|
254
|
+
expect(p.sources.find((s) => s.label === LOOSE_FILES)).toMatchObject({ failed: { files: 1, bytes: 5 }, skipped: { files: 1, bytes: 4 }, parked: 0 });
|
|
255
|
+
expect(journal().map((l) => [l.path, l.outcome, l.detail ?? null]).sort()).toEqual([
|
|
256
|
+
["Wedding 1998/a.jpg", "added", null],
|
|
257
|
+
["Wedding 1998/b.jpg", "duplicate", null],
|
|
258
|
+
["Wedding 1998/notes.xyz", "blocked", "not a photograph"],
|
|
259
|
+
["loose.jpg", "failed", "502 from prod"],
|
|
260
|
+
]);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("a dry run walks and journals nothing, and a sweep that throws records why before it rethrows", async () => {
|
|
264
|
+
put("a.jpg");
|
|
265
|
+
await sweepDropzone(dropzone(), async () => ({ kind: "stored" }), { stabilityMs: 0, dryRun: true, report: reporter() });
|
|
266
|
+
expect(progress()).toMatchObject({ sweep: { phase: "starting" }, sources: [] });
|
|
267
|
+
expect(existsSync(join(root, "state", FILES_JOURNAL))).toBe(false);
|
|
268
|
+
|
|
269
|
+
const onProgress = () => {
|
|
270
|
+
throw new Error("the store went away");
|
|
271
|
+
};
|
|
272
|
+
await expect(sweepDropzone(dropzone(), async () => ({ kind: "stored" }), { stabilityMs: 0, onProgress, report: reporter() })).rejects.toThrow();
|
|
273
|
+
expect(progress().sweep).toMatchObject({ state: "failed", error: "the store went away" });
|
|
274
|
+
});
|
|
275
|
+
});
|