From 19957bcf1b456ead33f1cae0cf2233cf3b386f1c Mon Sep 17 00:00:00 2001 From: theroimasters1-dev Date: Tue, 10 Nov 2026 02:04:45 +0530 Subject: [PATCH] fix(validate): recognize missing include paths with spaces (#526) --- CHANGELOG.md | 4 ++++ src/spec/load.ts | 9 ++++++--- test/load.test.ts | 29 ++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c91b7a5..0dccb86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/2.0.0/), ## [Unreleased] +### Fixed + +- `validate`: a top-level include path that starts with `./` or `../` and contains spaces, such as `policy: ./Carrier Policy.md` or `tasks: ./my tasks.yaml`, fails with a missing-file error when the target file does not exist, rather than becoming the policy string or failing with a schema type mismatch ([#526](https://github.com/sandtable-ai/sandtable/issues/526)). + ## [1.5.0] - 2026-11-09 A minor release with no breaking changes, and a security fix in the HTML reports: upgrade if you open reports built from domains or results files you didn't write. `sandtable judge` and `run --judge` score a run on judged criteria with a model, apart from pass^k, which they never change, and `sandtable calibrate` measures a judge against human labels. Clock dates reach the policy, param defaults, fault messages and `reply_includes`, and `report --markdown` writes a summary for a CI job or a pull request comment. diff --git a/src/spec/load.ts b/src/spec/load.ts index f29cafa..d42bc49 100644 --- a/src/spec/load.ts +++ b/src/spec/load.ts @@ -23,7 +23,7 @@ export class DomainNotFoundError extends DomainError {} /** * Load a domain from a directory containing sandtable.yaml (or the file itself). * Any top-level value that is a relative path to a .md/.yaml/.yml file is inlined, - * so policy, world and tasks can live in their own files. A one-token path to a missing file is an + * so policy, world and tasks can live in their own files. A relative path to a missing file is an * error, never the value itself: a misspelled `policy: ./polcy.md` would otherwise become the policy. */ export async function loadDomain(target: string): Promise { @@ -524,8 +524,11 @@ export function pendingReview(d: Domain): PendingItem[] { ]; } -/** One token ending in .md, .yaml or .yml: a path, so a missing file is an error rather than inline text. */ -const PATH = /^\S+\.(md|ya?ml)$/i; +/** + * A relative path ending in .md, .yaml or .yml: a single-token path, or a path starting with ./ or ../, + * so a missing file is an error rather than inline text. + */ +const PATH = /^(\S+|\.\.?[/\\][^\r\n]*)\.(md|ya?ml)$/i; function parseYaml(text: string, file: string): unknown { try { diff --git a/test/load.test.ts b/test/load.test.ts index ddafcce..60af566 100644 --- a/test/load.test.ts +++ b/test/load.test.ts @@ -47,10 +47,32 @@ describe("loadDomain includes", () => { await expect(loadDomain(dir)).rejects.toThrow(/tasks: \.\/task\.yaml not found/); }); - it("keeps inline text that merely mentions a file", async () => { + it("rejects a missing include path with spaces starting with ./ or ../", async () => { + const dir = copyOfClinic(); + edit(path.join(dir, "sandtable.yaml"), /^policy: \.\/policy\.md$/m, "policy: ./Carrier Policy.md"); + await expect(loadDomain(dir)).rejects.toThrow(/policy: \.\/Carrier Policy\.md not found/); + + const dir2 = copyOfClinic(); + edit(path.join(dir2, "sandtable.yaml"), /^policy: \.\/policy\.md$/m, "policy: ../shared/Carrier Policy.md"); + await expect(loadDomain(dir2)).rejects.toThrow(/policy: \.\.\/shared\/Carrier Policy\.md not found/); + + const dir3 = copyOfClinic(); + edit(path.join(dir3, "sandtable.yaml"), /^tasks: \.\/tasks\.yaml$/m, "tasks: ./my tasks.yaml"); + await expect(loadDomain(dir3)).rejects.toThrow(/tasks: \.\/my tasks\.yaml not found/); + }); + + it("keeps inline text that merely mentions a file or has spaces without ./", async () => { const dir = copyOfClinic(); edit(path.join(dir, "sandtable.yaml"), /^policy: \.\/policy\.md$/m, "policy: Follow the steps in policy.md"); expect((await loadDomain(dir)).policy).toBe("Follow the steps in policy.md"); + + const dir2 = copyOfClinic(); + edit(path.join(dir2, "sandtable.yaml"), /^policy: \.\/policy\.md$/m, "policy: See the handbook for carrier policy.md"); + expect((await loadDomain(dir2)).policy).toBe("See the handbook for carrier policy.md"); + + const dir3 = copyOfClinic(); + edit(path.join(dir3, "sandtable.yaml"), /^policy: \.\/policy\.md$/m, "policy: Carrier Policy.md"); + expect((await loadDomain(dir3)).policy).toBe("Carrier Policy.md"); }); it("inlines a file whose name has spaces", async () => { @@ -58,6 +80,11 @@ describe("loadDomain includes", () => { renameSync(path.join(dir, "policy.md"), path.join(dir, "Front Desk SOP.md")); edit(path.join(dir, "sandtable.yaml"), /^policy: \.\/policy\.md$/m, "policy: ./Front Desk SOP.md"); expect((await loadDomain(dir)).policy).toBe(readFileSync(path.resolve("examples/clinic/policy.md"), "utf8")); + + const dir2 = copyOfClinic(); + renameSync(path.join(dir2, "tasks.yaml"), path.join(dir2, "clinic tasks.yaml")); + edit(path.join(dir2, "sandtable.yaml"), /^tasks: \.\/tasks\.yaml$/m, "tasks: ./clinic tasks.yaml"); + expect((await loadDomain(dir2)).tasks.length).toBeGreaterThan(0); }); });