const __vite_ssr_import_0__ = await __vite_ssr_import__("/@fs/C:/Users/Admin/AppData/Local/npm-cache/_npx/69c381f8ad94b576/node_modules/vitest/dist/index.js", {"importedNames":["describe","expect","it"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__("/web/src/entities/job/progress.ts", {"importedNames":["currentLine","describeEta","describeMetrics","elapsedSeconds","failedStage","formatClock","formatMegabytes","formatSpan"]});


const stage = (over = {}) => ({
	key: "downloading",
	status: "running",
	weight: 1,
	fraction: .4,
	detail: "Downloading the section",
	items_done: 1,
	items_total: 5,
	metrics: {},
	error: null,
	...over
});
const detail = (over = {}) => ({
	stages: [stage()],
	current_stage: "downloading",
	overall: .3,
	eta_s: null,
	started_at: "2026-11-22T10:00:00Z",
	updated_at: "2026-11-22T10:05:00Z",
	items: [],
	...over
});
(0,__vite_ssr_import_0__.describe)("formatting", () => {
	(0,__vite_ssr_import_0__.it)("shows megabytes with one decimal and gigabytes from 10 GB", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.formatMegabytes)(3124e5)).toBe("312.4 MB");
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.formatMegabytes)(105e8)).toBe("10.5 GB");
	});
	(0,__vite_ssr_import_0__.it)("formats spans and video positions", () => {
		(0,__vite_ssr_import_0__.expect)([
			(0,__vite_ssr_import_1__.formatSpan)(45),
			(0,__vite_ssr_import_1__.formatSpan)(83),
			(0,__vite_ssr_import_1__.formatSpan)(3900),
			(0,__vite_ssr_import_1__.formatSpan)(-3)
		]).toEqual([
			"45s",
			"1m 23s",
			"1h 05m",
			"0s"
		]);
		(0,__vite_ssr_import_0__.expect)([(0,__vite_ssr_import_1__.formatClock)(129), (0,__vite_ssr_import_1__.formatClock)(3729)]).toEqual(["02:09", "1:02:09"]);
	});
});
(0,__vite_ssr_import_0__.describe)("describeMetrics", () => {
	(0,__vite_ssr_import_0__.it)("turns download figures into done/total and speed", () => {
		const parts = (0,__vite_ssr_import_1__.describeMetrics)(stage({ metrics: {
			bytes_done: 3124e5,
			bytes_total: 82e7,
			bytes_per_s: 61e5
		} }));
		(0,__vite_ssr_import_0__.expect)(parts).toEqual([{
			kind: "bytes",
			done: "312.4",
			total: "820.0 MB"
		}, {
			kind: "speed",
			perSecond: "6.1 MB/s"
		}]);
	});
	(0,__vite_ssr_import_0__.it)("leaves the total out when it is unknown, never inventing one", () => {
		const parts = (0,__vite_ssr_import_1__.describeMetrics)(stage({ metrics: { bytes_done: 5e6 } }));
		(0,__vite_ssr_import_0__.expect)(parts).toEqual([{
			kind: "bytes",
			done: "5.0",
			total: null
		}]);
	});
	(0,__vite_ssr_import_0__.it)("covers chat, video time and the render speed", () => {
		const metrics = {
			messages: 8400,
			seconds_done: 129,
			seconds_total: 7390,
			speed_x: 2.44
		};
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.describeMetrics)(stage({ metrics }))).toEqual([
			{
				kind: "messages",
				count: 8400
			},
			{
				kind: "video",
				done: "02:09",
				total: "2:03:10"
			},
			{
				kind: "realtime",
				times: "2.4"
			}
		]);
	});
	(0,__vite_ssr_import_0__.it)("is empty without metrics", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.describeMetrics)(stage())).toEqual([]);
	});
});
(0,__vite_ssr_import_0__.describe)("describeEta", () => {
	(0,__vite_ssr_import_0__.it)("says estimating while a running job has no number", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.describeEta)("running", detail())).toEqual({ kind: "estimating" });
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.describeEta)("queued", null)).toEqual({ kind: "estimating" });
	});
	(0,__vite_ssr_import_0__.it)("shows the time left once the server has one", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.describeEta)("running", detail({ eta_s: 83 }))).toEqual({
			kind: "left",
			text: "1m 23s"
		});
	});
	(0,__vite_ssr_import_0__.it)("shows nothing for a finished job", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.describeEta)("succeeded", detail({ eta_s: 0 }))).toEqual({ kind: "none" });
	});
});
(0,__vite_ssr_import_0__.describe)("elapsedSeconds", () => {
	(0,__vite_ssr_import_0__.it)("counts up to now while running and stops at the last update when finished", () => {
		const d = detail();
		const now = new Date("2026-11-22T10:10:00Z").getTime();
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.elapsedSeconds)(d, false, now)).toBe(600);
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.elapsedSeconds)(d, true, now)).toBe(300);
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.elapsedSeconds)(detail({ started_at: "nope" }), false, now)).toBe(0);
	});
});
(0,__vite_ssr_import_0__.describe)("currentLine and failedStage", () => {
	const job = (d, step = "Working") => ({
		id: "1",
		kind: "scan_vod",
		status: "running",
		progress: .3,
		step,
		error: null,
		result_ref: null,
		params: {},
		created_at: "",
		updated_at: "",
		detail: d
	});
	(0,__vite_ssr_import_0__.it)("uses the current stage's sentence and falls back to the step", () => {
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.currentLine)(job(detail()))).toBe("Downloading the section");
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.currentLine)(job(null))).toBe("Working");
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.currentLine)(job(detail({ current_stage: null })))).toBe("Working");
	});
	(0,__vite_ssr_import_0__.it)("finds the failed stage", () => {
		const failed = stage({
			status: "failed",
			error: "boom"
		});
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.failedStage)(detail({ stages: [stage({ status: "done" }), failed] }))).toBe(failed);
		(0,__vite_ssr_import_0__.expect)((0,__vite_ssr_import_1__.failedStage)(null)).toBeNull();
	});
});

//# vitestCache=W3siZmlsZSI6IjEiLCJpZCI6IjEiLCJpbXBvcnRzIjoiMiIsIm1hcHBpbmdzIjpmYWxzZSwiZGVwcyI6IjMiLCJkeW5hbWlj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,MAAM,SAAS,MAAM;GAAE,QAAQ;GAAU,OAAO;EAAO,CAAC;EACxD,iCAAO,sCAAY,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,OAAO,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM;EACxF,iCAAO,sCAAY,IAAI,CAAC,CAAC,CAAC,SAAS;CACrC,CAAC;AACH,CAAC","names":[],"ignoreList":[],"sources":["progress.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\n\nimport type { Job } from \"./api\";\nimport {\n  currentLine,\n  describeEta,\n  describeMetrics,\n  elapsedSeconds,\n  failedStage,\n  formatClock,\n  formatMegabytes,\n  formatSpan,\n  type JobDetail,\n  type Stage,\n} from \"./progress\";\n\nconst stage = (over: Partial<Stage> = {}): Stage => ({\n  key: \"downloading\",\n  status: \"running\",\n  weight: 1,\n  fraction: 0.4,\n  detail: \"Downloading the section\",\n  items_done: 1,\n  items_total: 5,\n  metrics: {},\n  error: null,\n  ...over,\n});\n\nconst detail = (over: Partial<JobDetail> = {}): JobDetail => ({\n  stages: [stage()],\n  current_stage: \"downloading\",\n  overall: 0.3,\n  eta_s: null,\n  started_at: \"2026-11-22T10:00:00Z\",\n  updated_at: \"2026-11-22T10:05:00Z\",\n  items: [],\n  ...over,\n});\n\ndescribe(\"formatting\", () => {\n  it(\"shows megabytes with one decimal and gigabytes from 10 GB\", () => {\n    expect(formatMegabytes(312_400_000)).toBe(\"312.4 MB\");\n    expect(formatMegabytes(10_500_000_000)).toBe(\"10.5 GB\");\n  });\n  it(\"formats spans and video positions\", () => {\n    expect([formatSpan(45), formatSpan(83), formatSpan(3900), formatSpan(-3)]).toEqual([\"45s\", \"1m 23s\", \"1h 05m\", \"0s\"]);\n    expect([formatClock(129), formatClock(3729)]).toEqual([\"02:09\", \"1:02:09\"]);\n  });\n});\n\ndescribe(\"describeMetrics\", () => {\n  it(\"turns download figures into done/total and speed\", () => {\n    const parts = describeMetrics(\n      stage({ metrics: { bytes_done: 312_400_000, bytes_total: 820_000_000, bytes_per_s: 6_100_000 } }),\n    );\n    expect(parts).toEqual([\n      { kind: \"bytes\", done: \"312.4\", total: \"820.0 MB\" },\n      { kind: \"speed\", perSecond: \"6.1 MB/s\" },\n    ]);\n  });\n  it(\"leaves the total out when it is unknown, never inventing one\", () => {\n    const parts = describeMetrics(stage({ metrics: { bytes_done: 5_000_000 } }));\n    expect(parts).toEqual([{ kind: \"bytes\", done: \"5.0\", total: null }]);\n  });\n  it(\"covers chat, video time and the render speed\", () => {\n    const metrics = { messages: 8400, seconds_done: 129, seconds_total: 7390, speed_x: 2.44 };\n    expect(describeMetrics(stage({ metrics }))).toEqual([\n      { kind: \"messages\", count: 8400 },\n      { kind: \"video\", done: \"02:09\", total: \"2:03:10\" },\n      { kind: \"realtime\", times: \"2.4\" },\n    ]);\n  });\n  it(\"is empty without metrics\", () => {\n    expect(describeMetrics(stage())).toEqual([]);\n  });\n});\n\ndescribe(\"describeEta\", () => {\n  it(\"says estimating while a running job has no number\", () => {\n    expect(describeEta(\"running\", detail())).toEqual({ kind: \"estimating\" });\n    expect(describeEta(\"queued\", null)).toEqual({ kind: \"estimating\" });\n  });\n  it(\"shows the time left once the server has one\", () => {\n    expect(describeEta(\"running\", detail({ eta_s: 83 }))).toEqual({ kind: \"left\", text: \"1m 23s\" });\n  });\n  it(\"shows nothing for a finished job\", () => {\n    expect(describeEta(\"succeeded\", detail({ eta_s: 0 }))).toEqual({ kind: \"none\" });\n  });\n});\n\ndescribe(\"elapsedSeconds\", () => {\n  it(\"counts up to now while running and stops at the last update when finished\", () => {\n    const d = detail();\n    const now = new Date(\"2026-11-22T10:10:00Z\").getTime();\n    expect(elapsedSeconds(d, false, now)).toBe(600);\n    expect(elapsedSeconds(d, true, now)).toBe(300);\n    expect(elapsedSeconds(detail({ started_at: \"nope\" }), false, now)).toBe(0);\n  });\n});\n\ndescribe(\"currentLine and failedStage\", () => {\n  const job = (d: JobDetail | null, step = \"Working\"): Job => ({\n    id: \"1\",\n    kind: \"scan_vod\",\n    status: \"running\",\n    progress: 0.3,\n    step,\n    error: null,\n    result_ref: null,\n    params: {},\n    created_at: \"\",\n    updated_at: \"\",\n    detail: d,\n  });\n  it(\"uses the current stage's sentence and falls back to the step\", () => {\n    expect(currentLine(job(detail()))).toBe(\"Downloading the section\");\n    expect(currentLine(job(null))).toBe(\"Working\");\n    expect(currentLine(job(detail({ current_stage: null })))).toBe(\"Working\");\n  });\n  it(\"finds the failed stage\", () => {\n    const failed = stage({ status: \"failed\", error: \"boom\" });\n    expect(failedStage(detail({ stages: [stage({ status: \"done\" }), failed] }))).toBe(failed);\n    expect(failedStage(null)).toBeNull();\n  });\n});\n"],"file":"/web/src/entities/job/progress.test.ts"}