mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 11:02:26 +00:00
test(scripts): route prompt snapshot helper changes
This commit is contained in:
@@ -19,6 +19,8 @@ import {
|
||||
createPnpmManagedCommand,
|
||||
createTargetedCoreLintCommand,
|
||||
shouldDelegateChangedCheckToCrabbox,
|
||||
shouldRunPromptSnapshotCheck,
|
||||
shouldRunPromptSnapshotOwnerTest,
|
||||
shouldRunShrinkwrapGuard,
|
||||
shouldRunTestTempCreationReport,
|
||||
createShrinkwrapGuardCommand,
|
||||
@@ -1295,6 +1297,45 @@ describe("scripts/changed-lanes", () => {
|
||||
expect(plan.commands.map((command) => command.args[0])).not.toContain("deps:shrinkwrap:check");
|
||||
});
|
||||
|
||||
it("runs prompt snapshot drift checks for prompt snapshot generator surfaces", () => {
|
||||
expect(
|
||||
shouldRunPromptSnapshotCheck([
|
||||
"scripts/generate-prompt-snapshots.ts",
|
||||
"test/helpers/agents/happy-path-prompt-snapshots.ts",
|
||||
"test/fixtures/agents/prompt-snapshots/runtime-happy-path/telegram-direct-codex-message-tool.md",
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
const result = detectChangedLanes(["test/helpers/agents/happy-path-prompt-snapshots.ts"]);
|
||||
const plan = createChangedCheckPlan(result);
|
||||
|
||||
expect(plan.commands).toContainEqual({
|
||||
name: "prompt snapshot drift",
|
||||
args: ["prompt:snapshots:check"],
|
||||
});
|
||||
expect(plan.commands).toContainEqual({
|
||||
name: "prompt snapshot owner test",
|
||||
args: ["test:serial", "test/scripts/prompt-snapshots.test.ts"],
|
||||
});
|
||||
});
|
||||
|
||||
it("runs the prompt snapshot owner test for model fixture generator surfaces", () => {
|
||||
expect(
|
||||
shouldRunPromptSnapshotOwnerTest([
|
||||
"scripts/sync-codex-model-prompt-fixture.ts",
|
||||
"test/fixtures/agents/prompt-snapshots/codex-model-catalog/gpt-5.5.pragmatic.source.json",
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
const result = detectChangedLanes(["scripts/sync-codex-model-prompt-fixture.ts"]);
|
||||
const plan = createChangedCheckPlan(result);
|
||||
|
||||
expect(plan.commands).toContainEqual({
|
||||
name: "prompt snapshot owner test",
|
||||
args: ["test:serial", "test/scripts/prompt-snapshots.test.ts"],
|
||||
});
|
||||
});
|
||||
|
||||
it("guards release metadata package changes to the top-level version field", () => {
|
||||
const dir = makeTempRepoRoot(tempDirs, "openclaw-release-metadata-");
|
||||
git(dir, ["init", "-q", "--initial-branch=main"]);
|
||||
|
||||
@@ -4,8 +4,10 @@ import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createFormattedPromptSnapshotFiles } from "../../scripts/generate-prompt-snapshots.js";
|
||||
import { deleteStalePromptSnapshotFiles } from "../../scripts/prompt-snapshot-files.js";
|
||||
import {
|
||||
CODEX_MODEL_PROMPT_FIXTURE_DIR as SYNC_CODEX_MODEL_PROMPT_FIXTURE_DIR,
|
||||
defaultCatalogPathCandidates,
|
||||
findDefaultCatalogPath,
|
||||
renderCodexModelInstructions,
|
||||
@@ -104,6 +106,10 @@ function listFindCommittedPromptSnapshotFiles(): string[] | null {
|
||||
}
|
||||
|
||||
describe("happy path prompt snapshots", () => {
|
||||
it("loads the generator entrypoint used by the prompt snapshot check", () => {
|
||||
expect(createFormattedPromptSnapshotFiles).toEqual(expect.any(Function));
|
||||
});
|
||||
|
||||
it("lists committed Codex prompt snapshot artifacts without scanning directories in-process", () => {
|
||||
expectNoReaddirSyncDuring(() => {
|
||||
const committed = listCommittedPromptSnapshotFiles();
|
||||
@@ -213,6 +219,7 @@ describe("happy path prompt snapshots", () => {
|
||||
});
|
||||
|
||||
it("keeps the Codex model prompt fixture next to its source metadata", () => {
|
||||
expect(SYNC_CODEX_MODEL_PROMPT_FIXTURE_DIR).toBe(CODEX_MODEL_PROMPT_FIXTURE_DIR);
|
||||
expect(
|
||||
fs.existsSync(path.join(CODEX_MODEL_PROMPT_FIXTURE_DIR, "gpt-5.5.pragmatic.instructions.md")),
|
||||
).toBe(true);
|
||||
@@ -295,4 +302,59 @@ describe("happy path prompt snapshots", () => {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("writes Codex model prompt fixtures from an explicit catalog", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-codex-catalog-write-"));
|
||||
try {
|
||||
const catalogPath = path.join(root, "models_cache.json");
|
||||
const outputDir = path.join(root, "out");
|
||||
fs.writeFileSync(
|
||||
catalogPath,
|
||||
JSON.stringify({
|
||||
models: [
|
||||
{
|
||||
slug: "gpt-5.5",
|
||||
model_messages: {
|
||||
instructions_template: "System\n{{ personality }}\nEnd",
|
||||
instructions_variables: {
|
||||
personality_pragmatic: "Use terse engineering judgement.",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const result = await runCodexModelPromptFixtureSync([
|
||||
"--catalog",
|
||||
catalogPath,
|
||||
"--source-label",
|
||||
"<test-catalog>",
|
||||
"--catalog-git-head",
|
||||
"abc123",
|
||||
"--out-dir",
|
||||
outputDir,
|
||||
]);
|
||||
|
||||
expect(result.status).toBe("written");
|
||||
expect(
|
||||
fs.readFileSync(path.join(outputDir, "gpt-5.5.pragmatic.instructions.md"), "utf8"),
|
||||
).toBe("System\nUse terse engineering judgement.\nEnd\n");
|
||||
expect(
|
||||
JSON.parse(fs.readFileSync(path.join(outputDir, "gpt-5.5.pragmatic.source.json"), "utf8")),
|
||||
).toEqual({
|
||||
model: "gpt-5.5",
|
||||
personality: "pragmatic",
|
||||
source: {
|
||||
catalogPath: "<test-catalog>",
|
||||
catalogKind: "models_cache",
|
||||
catalogGitHead: "abc123",
|
||||
field:
|
||||
"model_messages.instructions_template + model_messages.instructions_variables.personality_pragmatic",
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3407,6 +3407,22 @@ describe("scripts/test-projects changed-target routing", () => {
|
||||
expect(repoSourceReads.length).toBeLessThan(100);
|
||||
});
|
||||
|
||||
it("routes prompt snapshot generator helper edits to the owner test", () => {
|
||||
for (const target of [
|
||||
"scripts/generate-prompt-snapshots.ts",
|
||||
"scripts/prompt-snapshot-files.ts",
|
||||
"scripts/sync-codex-model-prompt-fixture.ts",
|
||||
"test/helpers/agents/happy-path-prompt-snapshots.ts",
|
||||
"test/fixtures/agents/prompt-snapshots/codex-model-catalog/gpt-5.5.pragmatic.source.json",
|
||||
"test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/telegram-direct-codex-message-tool.md",
|
||||
]) {
|
||||
expect(resolveChangedTestTargetPlan([target])).toEqual({
|
||||
mode: "targets",
|
||||
targets: ["test/scripts/prompt-snapshots.test.ts"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
"test/vitest/vitest.agents-core.config.ts",
|
||||
"test/vitest/vitest.agents-embedded-agent.config.ts",
|
||||
|
||||
Reference in New Issue
Block a user