源码快照 @ 2026-09-02 (source-only, 剔除非源码素材)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import type { ScreenshotArtifact } from "@openwork/test-evidence";
|
||||
|
||||
/** Transient product chrome that must never ship in a docs screenshot. */
|
||||
export const DEFAULT_NEVER = [
|
||||
"new notifications",
|
||||
"opencode_unconfigured",
|
||||
"OpenCode base URL",
|
||||
"Loading commands",
|
||||
"Pulling in the latest messages",
|
||||
"Checking workspace access",
|
||||
] as const;
|
||||
|
||||
export type Gate = (artifact: ScreenshotArtifact) => boolean;
|
||||
|
||||
export interface GateOptions {
|
||||
expect: readonly string[];
|
||||
never?: readonly string[];
|
||||
route?: RegExp;
|
||||
}
|
||||
|
||||
/** Build a side-effect-free acceptance predicate over a captured artifact. */
|
||||
export function gate(options: GateOptions): Gate {
|
||||
const never = [...DEFAULT_NEVER, ...(options.never ?? [])];
|
||||
return (artifact) => {
|
||||
if (!options.expect.every((text) => artifact.visibleText.includes(text))) return false;
|
||||
if (never.some((text) => artifact.visibleText.includes(text))) return false;
|
||||
if (!options.route) return true;
|
||||
try {
|
||||
return options.route.test(decodeURIComponent(artifact.route));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user