From 8bf22990921554b56bc28dc9e9b7aa8049986fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Wed, 22 Apr 2026 18:45:02 -0400 Subject: [PATCH] test(prompt): lock cacheable system prefix --- .../prompt-manager-classification.test.ts | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/unit/prompt-manager-classification.test.ts b/tests/unit/prompt-manager-classification.test.ts index 322679a6..9d752275 100644 --- a/tests/unit/prompt-manager-classification.test.ts +++ b/tests/unit/prompt-manager-classification.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from "vitest"; -import { buildSystemPrompt } from "../../src/main/prompt-builder/index"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { buildSystemPrompt, buildTaskPrompt } from "../../src/main/prompt-builder/index"; import type { PromptContext } from "../../src/main/prompt-builder/index"; function buildCtx(overrides: Partial = {}): PromptContext { @@ -72,6 +72,10 @@ function buildCtx(overrides: Partial = {}): PromptContext { } describe("buildSystemPrompt leadership classification", () => { + afterEach(() => { + vi.useRealTimers(); + }); + it("treats first-layer executive leaders as managers even before they have direct reports", () => { const prompt = buildSystemPrompt(buildCtx()); @@ -95,4 +99,31 @@ describe("buildSystemPrompt leadership classification", () => { expect(prompt).toContain("Use for A&B "checks" and 'snapshots'."); expect(prompt).toContain("/tmp/skills/ui<review>&qa/SKILL.md"); }); + + it("keeps the system prompt byte-stable across wall-clock changes", () => { + const ctx = buildCtx(); + + vi.useFakeTimers(); + vi.setSystemTime(new Date("2026-04-22T10:00:00.000Z")); + const first = buildSystemPrompt(ctx); + vi.setSystemTime(new Date("2026-04-23T23:59:00.000Z")); + const second = buildSystemPrompt(ctx); + + expect(second).toBe(first); + }); + + it("keeps volatile task context after the cacheable system prefix", () => { + const ctx = buildCtx({ wakeReason: "timer" }); + const systemPrompt = buildSystemPrompt(ctx); + + vi.useFakeTimers(); + vi.setSystemTime(new Date("2026-04-22T10:00:00.000Z")); + const first = buildTaskPrompt(ctx); + vi.setSystemTime(new Date("2026-04-23T23:59:00.000Z")); + const second = buildTaskPrompt(ctx); + + expect(first.slice(0, systemPrompt.length)).toBe(systemPrompt); + expect(second.slice(0, systemPrompt.length)).toBe(systemPrompt); + expect(first.slice(systemPrompt.length)).not.toBe(second.slice(systemPrompt.length)); + }); });