Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/harness-learning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { symlinkFixtureAvailable } from "./windows-symlink-capability.js";
import {
HarnessLearningStore,
reviewHarnessEvidence,
Expand Down Expand Up @@ -229,6 +230,7 @@ test("dangling journal symlink is corrupt, not an empty journal", (t) => {
const s = store(t);
const project = "kmj-codebridge";
const file = s.filename(project);
if (!symlinkFixtureAvailable(t, path.dirname(file))) return;
const missingTarget = path.join(path.dirname(file), "missing-journal.json");
fs.symlinkSync(missingTarget, file);
assert.equal(fs.existsSync(file), false);
Expand All @@ -252,6 +254,7 @@ test("dangling journal symlink is corrupt, not an empty journal", (t) => {
test("symlinked or corrupt journal fails closed", (t) => {
const s = store(t);
const p = "kmj-codebridge";
if (!symlinkFixtureAvailable(t, path.dirname(s.filename(p)))) return;
s.record(p, {
...evidence,
requestKey: "first",
Expand All @@ -274,6 +277,7 @@ test("symlinked or corrupt journal fails closed", (t) => {
test("journal path swap between lstat and open fails closed", (t) => {
const s = store(t);
const project = "kmj-codebridge";
if (!symlinkFixtureAvailable(t, path.dirname(s.filename(project)))) return;
s.record(project, {
...evidence,
requestKey: "initial",
Expand Down
24 changes: 24 additions & 0 deletions tests/windows-symlink-capability.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "node:fs";
import path from "node:path";

/**
* Only symbolic-link fixture creation is optional on non-admin Windows
Expand Down Expand Up @@ -29,3 +30,26 @@ export function tryFileSymlink(t, target, link) {
return false;
}
}

/**
* For tests that create the link inside a hook or helper: probe once up front.
* Returns false (after t.skip) only on a non-audited Windows workstation.
*/
export function symlinkFixtureAvailable(t, dir) {
const target = path.join(dir, "symlink-probe-target");
const link = path.join(dir, "symlink-probe-link");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(target, "probe");
try {
if (!tryFileSymlink(t, target, link)) {
t.skip(
"Windows cannot create symlink fixture; security assertion NOT EXECUTED",
);
return false;
}
return true;
} finally {
fs.rmSync(link, { force: true });
fs.rmSync(target, { force: true });
}
}