|
1 | 1 | import type { CheckProgress } from "../utils/checkProgress.js"; |
2 | 2 | import { runCommand } from "citty"; |
3 | | -import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { |
| 4 | + mkdirSync, |
| 5 | + mkdtempSync, |
| 6 | + readFileSync, |
| 7 | + rmSync, |
| 8 | + statSync, |
| 9 | + symlinkSync, |
| 10 | + utimesSync, |
| 11 | + writeFileSync, |
| 12 | +} from "node:fs"; |
4 | 13 | import { tmpdir } from "node:os"; |
5 | 14 | import { join } from "node:path"; |
6 | 15 | import { afterEach, describe, expect, it, vi } from "vitest"; |
@@ -544,6 +553,24 @@ it("--budget sets when the whole check stops, its report time kept back, counted |
544 | 553 | expect(runPipeline.mock.calls[1]?.[1].budget).toBeUndefined(); |
545 | 554 | }); |
546 | 555 |
|
| 556 | +it("--no-craft reaches the pipeline as craft: false, and the craft pass is on without it", async () => { |
| 557 | + const { report } = await runScenario(fakeDriver()); |
| 558 | + const runPipeline = vi.fn(async (_project: ProjectDir, _options: CheckOptions) => report); |
| 559 | + vi.spyOn(console, "log").mockImplementation(() => undefined); |
| 560 | + const command = createCheckCommand({ |
| 561 | + resolveProject: () => PROJECT, |
| 562 | + runPipeline, |
| 563 | + prepareMedia: vi.fn(async () => []), |
| 564 | + withMeta: (value) => value, |
| 565 | + }); |
| 566 | + |
| 567 | + await runCommand(command, { rawArgs: ["--json", "--no-craft"] }); |
| 568 | + await runCommand(command, { rawArgs: ["--json"] }); |
| 569 | + |
| 570 | + expect(runPipeline.mock.calls[0]?.[1].craft).toBe(false); |
| 571 | + expect(runPipeline.mock.calls[1]?.[1].craft).toBe(true); |
| 572 | +}); |
| 573 | + |
547 | 574 | it("parses the caption-zone grammar and enables the frame gate", async () => { |
548 | 575 | const { report } = await runScenario(fakeDriver()); |
549 | 576 | const runPipeline = vi.fn(async (_project: ProjectDir, _options: CheckOptions) => report); |
@@ -3046,6 +3073,15 @@ describe("check pipeline", () => { |
3046 | 3073 | expect(checkExitCode(strict.report)).toBe(0); |
3047 | 3074 | }); |
3048 | 3075 |
|
| 3076 | + it("--no-craft never samples the craft frames and the report says the pass was skipped", async () => { |
| 3077 | + const driver = craftDriver(); |
| 3078 | + const { report } = await runScenario(driver, { craft: false }); |
| 3079 | + |
| 3080 | + expect(driver.collectCraftFrame).not.toHaveBeenCalled(); |
| 3081 | + expect(report.craft.enabled).toBe(false); |
| 3082 | + expect(report.craft.findings).toEqual([]); |
| 3083 | + }); |
| 3084 | + |
3049 | 3085 | it("seeks each craft frame with WebGL draws on, so a redrawn canvas reads as moving", async () => { |
3050 | 3086 | const driver = craftDriver(); |
3051 | 3087 | await runScenario(driver); |
@@ -3991,6 +4027,177 @@ it("applies transition sample limits within the requested range", async () => { |
3991 | 4027 | expect(report.layout.transitionSamplesDropped).toBe(3); |
3992 | 4028 | }); |
3993 | 4029 |
|
| 4030 | +describe("check cache", () => { |
| 4031 | + const dirs: string[] = []; |
| 4032 | + afterEach(() => { |
| 4033 | + vi.unstubAllEnvs(); |
| 4034 | + for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }); |
| 4035 | + }); |
| 4036 | + |
| 4037 | + function setup(report: CheckReport) { |
| 4038 | + const browser: { identity: string | undefined } = { identity: "chrome:1" }; |
| 4039 | + const dir = mkdtempSync(join(tmpdir(), "hf-check-cache-")); |
| 4040 | + dirs.push(dir); |
| 4041 | + writeFileSync(join(dir, "index.html"), "<html>one</html>"); |
| 4042 | + const runPipeline = vi.fn(async (_project: ProjectDir, _options: CheckOptions) => report); |
| 4043 | + const command = createCheckCommand({ |
| 4044 | + resolveProject: () => ({ dir, name: "p", indexPath: join(dir, "index.html") }), |
| 4045 | + runPipeline, |
| 4046 | + prepareMedia: vi.fn(async () => []), |
| 4047 | + withMeta: (value) => value, |
| 4048 | + browserIdentity: async () => browser.identity, |
| 4049 | + }); |
| 4050 | + vi.spyOn(console, "log").mockImplementation(() => undefined); |
| 4051 | + return { |
| 4052 | + dir, |
| 4053 | + browser, |
| 4054 | + runPipeline, |
| 4055 | + run: (...flags: string[]) => runCommand(command, { rawArgs: ["--json", ...flags] }), |
| 4056 | + }; |
| 4057 | + } |
| 4058 | + |
| 4059 | + it("answers an unchanged tree from the last pass without running the pipeline", async () => { |
| 4060 | + const { runPipeline, run } = setup(reportWithFindings()); |
| 4061 | + await run(); |
| 4062 | + await run(); |
| 4063 | + expect(runPipeline).toHaveBeenCalledTimes(1); |
| 4064 | + }); |
| 4065 | + |
| 4066 | + it("re-runs after one byte of the composition changes", async () => { |
| 4067 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4068 | + await run(); |
| 4069 | + writeFileSync(join(dir, "index.html"), "<html>onf</html>"); |
| 4070 | + await run(); |
| 4071 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4072 | + }); |
| 4073 | + |
| 4074 | + it("never stores a failure", async () => { |
| 4075 | + const { runPipeline, run } = setup(reportWithFindings({ ok: false })); |
| 4076 | + await run(); |
| 4077 | + await run(); |
| 4078 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4079 | + }); |
| 4080 | + |
| 4081 | + it("never stores a pass whose browser did not run", async () => { |
| 4082 | + const { runPipeline, run } = setup(reportWithFindings({ browserSkipped: true })); |
| 4083 | + await run(); |
| 4084 | + await run(); |
| 4085 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4086 | + }); |
| 4087 | + |
| 4088 | + it("does not store a pass for a tree that changed while it was being checked", async () => { |
| 4089 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4090 | + runPipeline.mockImplementationOnce(async () => { |
| 4091 | + writeFileSync(join(dir, "index.html"), "<html>written by someone else</html>"); |
| 4092 | + return reportWithFindings(); |
| 4093 | + }); |
| 4094 | + await run(); |
| 4095 | + writeFileSync(join(dir, "index.html"), "<html>one</html>"); |
| 4096 | + await run(); |
| 4097 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4098 | + }); |
| 4099 | + |
| 4100 | + it("re-runs a large file changed to the same size with its mtime put back", async () => { |
| 4101 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4102 | + const big = join(dir, "clip.bin"); |
| 4103 | + const mtime = 1_700_000_000; |
| 4104 | + writeFileSync(big, Buffer.alloc(3 * 1024 * 1024, 1)); |
| 4105 | + utimesSync(big, mtime, mtime); |
| 4106 | + await run(); |
| 4107 | + const writtenAt = statSync(big).ctimeMs; |
| 4108 | + await vi.waitFor( |
| 4109 | + () => { |
| 4110 | + writeFileSync(big, Buffer.alloc(3 * 1024 * 1024, 2)); |
| 4111 | + utimesSync(big, mtime, mtime); |
| 4112 | + if (statSync(big).ctimeMs === writtenAt) throw new Error("the clock has not ticked"); |
| 4113 | + }, |
| 4114 | + { interval: 1 }, |
| 4115 | + ); |
| 4116 | + await run(); |
| 4117 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4118 | + }); |
| 4119 | + |
| 4120 | + it("never caches a project with node_modules or a linked directory", async () => { |
| 4121 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4122 | + mkdirSync(join(dir, "node_modules")); |
| 4123 | + await run(); |
| 4124 | + await run(); |
| 4125 | + rmSync(join(dir, "node_modules"), { recursive: true }); |
| 4126 | + mkdirSync(join(dir, "real")); |
| 4127 | + symlinkSync(join(dir, "real"), join(dir, "linked"), "dir"); |
| 4128 | + await run(); |
| 4129 | + await run(); |
| 4130 | + expect(runPipeline).toHaveBeenCalledTimes(4); |
| 4131 | + }); |
| 4132 | + |
| 4133 | + it("re-runs when --timeout or the runtime URL changes", async () => { |
| 4134 | + const { runPipeline, run } = setup(reportWithFindings()); |
| 4135 | + vi.stubEnv("HYPERFRAME_RUNTIME_URL", "http://localhost:1/runtime.js"); |
| 4136 | + await run(); |
| 4137 | + await run("--timeout", "20s"); |
| 4138 | + vi.stubEnv("HYPERFRAME_RUNTIME_URL", "http://localhost:2/runtime.js"); |
| 4139 | + await run(); |
| 4140 | + vi.unstubAllEnvs(); |
| 4141 | + expect(runPipeline).toHaveBeenCalledTimes(3); |
| 4142 | + }); |
| 4143 | + |
| 4144 | + it("re-runs when the browser binary changes, and never caches without one", async () => { |
| 4145 | + const { browser, runPipeline, run } = setup(reportWithFindings()); |
| 4146 | + await run(); |
| 4147 | + browser.identity = "chrome:2"; |
| 4148 | + await run(); |
| 4149 | + browser.identity = undefined; |
| 4150 | + await run(); |
| 4151 | + await run(); |
| 4152 | + expect(runPipeline).toHaveBeenCalledTimes(4); |
| 4153 | + }); |
| 4154 | + |
| 4155 | + it("re-runs when a script under .hyperframes changes, but not when the CLI's own files do", async () => { |
| 4156 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4157 | + mkdirSync(join(dir, ".hyperframes", "artifacts"), { recursive: true }); |
| 4158 | + writeFileSync(join(dir, ".hyperframes", "probe.js"), "console.log(1)"); |
| 4159 | + await run(); |
| 4160 | + writeFileSync(join(dir, ".hyperframes", "artifacts", "report.json"), "{}"); |
| 4161 | + await run(); |
| 4162 | + expect(runPipeline).toHaveBeenCalledTimes(1); |
| 4163 | + writeFileSync(join(dir, ".hyperframes", "probe.js"), "console.error(1)"); |
| 4164 | + await run(); |
| 4165 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4166 | + }); |
| 4167 | + |
| 4168 | + it("still hits when the check touches its video copies under .transcode-cache", async () => { |
| 4169 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4170 | + const copy = join(dir, ".transcode-cache", "clip.mp4"); |
| 4171 | + mkdirSync(join(dir, ".transcode-cache")); |
| 4172 | + writeFileSync(copy, Buffer.alloc(3 * 1024 * 1024, 1)); |
| 4173 | + runPipeline.mockImplementationOnce(async () => { |
| 4174 | + utimesSync(copy, new Date(), new Date()); |
| 4175 | + return reportWithFindings(); |
| 4176 | + }); |
| 4177 | + await run(); |
| 4178 | + await run(); |
| 4179 | + expect(runPipeline).toHaveBeenCalledTimes(1); |
| 4180 | + }); |
| 4181 | + |
| 4182 | + it("never caches a project whose .hyperframes links to another directory", async () => { |
| 4183 | + const { dir, runPipeline, run } = setup(reportWithFindings()); |
| 4184 | + mkdirSync(join(dir, "real")); |
| 4185 | + mkdirSync(join(dir, ".hyperframes")); |
| 4186 | + symlinkSync(join(dir, "real"), join(dir, ".hyperframes", "linked"), "dir"); |
| 4187 | + await run(); |
| 4188 | + await run(); |
| 4189 | + expect(runPipeline).toHaveBeenCalledTimes(2); |
| 4190 | + }); |
| 4191 | + |
| 4192 | + it("re-runs when the flags differ, or with --no-cache, or under --budget", async () => { |
| 4193 | + const { runPipeline, run } = setup(reportWithFindings()); |
| 4194 | + await run(); |
| 4195 | + await run("--strict"); |
| 4196 | + await run("--no-cache"); |
| 4197 | + await run("--budget", "8m"); |
| 4198 | + expect(runPipeline).toHaveBeenCalledTimes(4); |
| 4199 | + }); |
| 4200 | +}); |
3994 | 4201 | describe("check stopped by a signal", () => { |
3995 | 4202 | it("SIGTERM prints the report so far, then exits 143", async () => { |
3996 | 4203 | const { deps, runBrowserCheck } = dependencies(fakeDriver()); |
|
0 commit comments