@turri-dev/cli 0.3.1-next.f3b1920 → 0.4.1-next.2e3d7a6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/background-skills.js +2 -2
  2. package/dist/extension.js +4 -4
  3. package/dist/graph.js +1 -1
  4. package/dist/parse-cli.js +1 -1
  5. package/dist/plain/check.js +2 -2
  6. package/dist/regenerate/conformance-agents.js +2 -2
  7. package/dist/regenerate/diagnose.js +2 -1
  8. package/dist/regenerate/environment-error.js +7 -3
  9. package/dist/regenerate/launch.js +4 -2
  10. package/dist/regenerate/loop.js +9 -8
  11. package/dist/regenerate/paths.d.ts +12 -0
  12. package/dist/regenerate/paths.js +19 -2
  13. package/dist/regenerate/self-check.js +3 -2
  14. package/dist/regenerate/spec-map.js +3 -3
  15. package/dist/regenerate/spec-steps.js +3 -3
  16. package/dist/regenerate/test-scripts.d.ts +6 -0
  17. package/dist/regenerate/test-scripts.js +13 -5
  18. package/dist/regenerate/testing.js +2 -2
  19. package/dist/regenerate-cli.js +1 -1
  20. package/dist/skill.js +1 -1
  21. package/dist/test-plain-files.js +4 -9
  22. package/dist/tools.js +3 -2
  23. package/docs/installation.md +2 -2
  24. package/docs/regenerating.md +2 -0
  25. package/genome/rules/examples/integration-embedded-testing/run_conformance_tests_java.sh +12 -14
  26. package/genome/rules/examples/integration-embedded-testing/run_unittests_java.sh +10 -11
  27. package/genome/rules/integration-embedded-testing.md +4 -4
  28. package/genome/skills/implement-conformance-testing-script/SKILL.md +17 -9
  29. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +32 -17
  30. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +35 -39
  31. package/genome/skills/implement-unit-testing-script/SKILL.md +14 -6
  32. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +21 -11
  33. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +17 -13
  34. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { basename } from "node:path";
1
2
  import { Box, Text } from "@earendil-works/pi-tui";
2
3
  import { chatBusy } from "./chat-idle.js";
3
4
  /**
@@ -36,8 +37,7 @@ export function ownChanges(changed, kind) {
36
37
  if (kind === undefined)
37
38
  return changed;
38
39
  const scripts = kind === "unit" ? ["run_unittests"] : ["run_conformance_tests", "prepare_environment"];
39
- const name = (path) => path.split("/").at(-1) ?? path;
40
- return changed.filter((path) => scripts.some((script) => name(path).startsWith(script)) || /^config(\.turri)?(\.[^.]+)?\.yaml$/.test(name(path)));
40
+ return changed.filter((path) => scripts.some((script) => basename(path).startsWith(script)) || /^config(\.turri)?(\.[^.]+)?\.yaml$/.test(basename(path)));
41
41
  }
42
42
  /** The line a background run that did its work is drawn as. */
43
43
  export function doneLine(skill, changed, kind) {
package/dist/extension.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import "./terminal-images.js";
3
3
  import { moduleOfTestPlainFile, refuseTestPlainFile, testPlainFileRefusal } from "./test-plain-files.js";
4
4
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
5
- import { basename, dirname, join, relative, resolve } from "node:path";
5
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
6
6
  import { conversationCommand, conversationSettled, conversationWriting } from "./regenerate/conversation-writes.js";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { allocateImageId, Box, getCapabilities, getPngDimensions, isKeyRelease, isKeyRepeat, matchesKey, renderImage, Text, wrapTextWithAnsi } from "@earendil-works/pi-tui";
@@ -1669,10 +1669,10 @@ export function projectConfigBlock(root) {
1669
1669
  return "";
1670
1670
  const describe = (dir) => {
1671
1671
  const modules = moduleConfigsOf(dir);
1672
- const where = dir === root ? "" : ` (paths relative to ${relative(root, dir)}/)`;
1673
- const at = (name) => (dir === root ? name : `${relative(root, dir)}/${name}`);
1672
+ const where = dir === root ? "" : ` (paths relative to ${relative(root, dir)}${sep})`;
1673
+ const at = (name) => (dir === root ? name : join(relative(root, dir), name));
1674
1674
  return [
1675
- ...settings(readProjectConfig(dir), withConfigModule(undefined, () => findTestScripts(dir)), dir === root ? `${projectConfigFile(dir)}, for the specs here:` : `${relative(root, dir)}/${projectConfigFile(dir)}, for the specs in ${relative(root, dir)}/ - built in ${relative(root, dir)}/plain_modules:`, where, modules.length > 0 ? "project of module files" : "project"),
1675
+ ...settings(readProjectConfig(dir), withConfigModule(undefined, () => findTestScripts(dir)), dir === root ? `${projectConfigFile(dir)}, for the specs here:` : `${join(relative(root, dir), projectConfigFile(dir))}, for the specs in ${relative(root, dir)}${sep} - built in ${join(relative(root, dir), "plain_modules")}:`, where, modules.length > 0 ? "project of module files" : "project"),
1676
1676
  // A module's own file: over the project's, for it and every module built on it that has no file of its own.
1677
1677
  ...modules.flatMap((module) => [
1678
1678
  "",
package/dist/graph.js CHANGED
@@ -83,7 +83,7 @@ function stepPrompt(skill, step, critique, context) {
83
83
  "",
84
84
  // What the step names by path - its references, another skill to follow - is found from here.
85
85
  `This skill's own files are in ${skill.dir}: a path its steps name, such as references/<file>.md, is there. ` +
86
- `A skill it says to follow is beside it, in ${dirname(skill.dir)}/<skill name>/SKILL.md - read it and follow it.`,
86
+ `A skill it says to follow is beside it, in ${join(dirname(skill.dir), "<skill name>", "SKILL.md")} - read it and follow it.`,
87
87
  "",
88
88
  // The artifact exists for the gate's judges to read. Without a gate its reply is what the step gives,
89
89
  // and asking for a file is a tool call spent on what the reply already says.
package/dist/parse-cli.js CHANGED
@@ -12,7 +12,7 @@ test folder is refused: name its module.
12
12
  --template-dir <dir> extra template directory (repeatable)
13
13
  --json machine-readable output
14
14
 
15
- PLAIN_TEMPLATE_DIRS colon-separated template directories`;
15
+ PLAIN_TEMPLATE_DIRS template directories, separated as PATH is (: or ; on Windows)`;
16
16
  const argv = process.argv.slice(2);
17
17
  const templateDirs = [];
18
18
  const positional = [];
@@ -157,7 +157,7 @@ export function checkTestFolder(projectDir) {
157
157
  return undefined;
158
158
  const testDir = testDirOf(join(projectDir, `x${PLAIN_SOURCE_FILE_EXTENSION}`));
159
159
  return {
160
- file: `${shown(testDir, projectDir)}/`,
160
+ file: `${shown(testDir, projectDir)}${sep}`,
161
161
  ok: false,
162
162
  errorType: `${strays.length} test plain file${strays.length === 1 ? "" : "s"} outside a module's folder`,
163
163
  problems: strays.map((stray) => `${stray.file} - ${stray.problem}`),
@@ -212,7 +212,7 @@ function scenarioCounts(spec) {
212
212
  export function formatCheckResults(results) {
213
213
  const lines = [];
214
214
  for (const result of results) {
215
- const name = result.file.endsWith("/") ? result.file : basename(result.file);
215
+ const name = result.file.endsWith(sep) ? result.file : basename(result.file);
216
216
  if (result.ok) {
217
217
  const specs = result.functionalSpecs ?? [];
218
218
  const requires = result.requiredModules && result.requiredModules.length > 0 ? `, requires ${result.requiredModules.join(", ")}` : "";
@@ -5,7 +5,7 @@ import { defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
6
  import { ask, BEGIN, createExecutor } from "../pi.js";
7
7
  import { confinedTools } from "./confine.js";
8
- import { ensureInModulesScratch, modulesScratchDir } from "./paths.js";
8
+ import { ensureInModulesScratch, isWithin, modulesScratchDir } from "./paths.js";
9
9
  import { workspaceBlock } from "./workspace.js";
10
10
  import { reportActivity } from "./activity.js";
11
11
  import { runTiming, withTestingScripts } from "./test-scripts.js";
@@ -750,7 +750,7 @@ export async function judgeFailure(options) {
750
750
  const opened = (cited) => {
751
751
  // A file it opened, or one in a folder it listed or searched; cited as it was opened, or relative to the code or the tests.
752
752
  const candidates = [resolve(options.conformanceDir, cited), resolve(options.buildDir, cited)];
753
- return candidates.some((path) => [...openedPaths].some((seen) => path === seen || path.startsWith(`${seen}/`)));
753
+ return candidates.some((path) => [...openedPaths].some((seen) => isWithin(path, seen)));
754
754
  };
755
755
  const scriptText = options.testingScripts?.map((script) => script.content).join("\n");
756
756
  const before = { code: digestFiles(options.buildDir), tests: digestFiles(options.conformanceDir) };
@@ -1,4 +1,5 @@
1
1
  import { defineTool } from "@earendil-works/pi-coding-agent";
2
+ import { join } from "node:path";
2
3
  import { Type } from "typebox";
3
4
  import { ask, BEGIN, createExecutor } from "../pi.js";
4
5
  import { debugMode } from "../config.js";
@@ -70,7 +71,7 @@ export function diagnosisPrompt(options) {
70
71
  `- the project, in ${options.projectDir}: its .plain specs and templates, config.turri.yaml, the testing scripts, and`,
71
72
  " plain_modules - each module's code and conformance tests, the notes (.turri-notes.md in the code), the full",
72
73
  " outputs of the test runs (plain_modules/.turri/logs), and every agent's own log",
73
- ` (${options.projectDir}/.turri/debug) - newest last;`,
74
+ ` (${join(options.projectDir, ".turri", "debug")}) - newest last;`,
74
75
  ...(options.jobLog !== undefined ? [`- this job's own log: ${options.jobLog};`] : []),
75
76
  `- turri itself, in ${options.harnessDir}: its source (src/), its skills (genome/skills/), the ***plain authoring rules`,
76
77
  " (genome/rules/) and its docs (docs/) - so a failure that comes from the harness can be named as that.",
@@ -5,7 +5,7 @@ import { defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
6
  import { passedCredentials } from "./agent-env.js";
7
7
  import { missingToolchain } from "./test-scripts.js";
8
- import { MODULES_DIR } from "./paths.js";
8
+ import { isWithin, MODULES_DIR } from "./paths.js";
9
9
  import { reportActivity } from "./activity.js";
10
10
  import { LINUX_MACHINE, MACOS_MACHINE } from "./os-sandbox.js";
11
11
  /**
@@ -75,8 +75,12 @@ function toolchainFolder(path) {
75
75
  * the stop is the sandbox's, and the fix is a line of config - `toolchains:` - not an install.
76
76
  */
77
77
  export function sandboxGapOf(text, options = {}) {
78
+ const platform = options.platform ?? process.platform;
79
+ // The paths are read as Seatbelt's and bubblewrap's, from the error's text: Windows has no OS sandbox to hide one.
80
+ if (platform === "win32")
81
+ return undefined;
78
82
  const exists = options.exists ?? existsSync;
79
- const system = (options.platform ?? process.platform) === "darwin" ? MACOS_MACHINE : LINUX_MACHINE;
83
+ const system = platform === "darwin" ? MACOS_MACHINE : LINUX_MACHINE;
80
84
  const within = (path, root) => path === root || path.startsWith(`${root}/`);
81
85
  const named = [...text.matchAll(/(?:^|[\s'"`(=:])(\/[^\s'"`()<>,;]+)/g)].map((match) => match[1].replace(/[.:]+$/, ""));
82
86
  const isLock = (path) => LOCK_FILE.test(basename(path));
@@ -103,7 +107,7 @@ export function describeEnvironmentError(error, rerun) {
103
107
  if (gap?.access === "write") {
104
108
  const what = gap.lock === true ? `the lock file \`${gap.paths[0]}\`, which the build takes as it runs` : `\`${gap.paths[0]}\``;
105
109
  const home = homedir();
106
- const inHome = gap.paths[0] === home || gap.paths[0].startsWith(`${home}/`);
110
+ const inHome = isWithin(gap.paths[0], home);
107
111
  return [
108
112
  `**${error.moduleName} stopped: turri's sandbox kept its agents from writing ${what} - it is on this machine; nothing is missing, and nothing needs installing.**`,
109
113
  needed,
@@ -4,7 +4,7 @@ import { connect } from "node:net";
4
4
  import { dirname, join, relative } from "node:path";
5
5
  import { HISTORY_DIR } from "./lineage.js";
6
6
  import { NOTES_FILE } from "./notes.js";
7
- import { distDirFor, ensureInScratch, projectDirOf } from "./paths.js";
7
+ import { distDirFor, ensureInScratch, projectDirOf, slashed } from "./paths.js";
8
8
  import { findCodebaseTip } from "./requires.js";
9
9
  import { RECORD_FILE } from "./paths.js";
10
10
  function git(moduleDir, args) {
@@ -115,7 +115,9 @@ export function exportModule(plainFile, options = {}) {
115
115
  mkdirSync(dir, { recursive: true });
116
116
  for (const entry of readdirSync(dir))
117
117
  rmSync(join(dir, entry), { recursive: true, force: true });
118
- const exported = spawnSync("bash", ["-o", "pipefail", "-c", 'git --git-dir "$1" archive --format=tar "$2" | tar -x -f - -C "$3"', "export", join(moduleDir, HISTORY_DIR), `${commit}:code`, dir], { encoding: "utf8" });
118
+ // tar extracts where it runs, given no path: GNU tar reads escapes in the paths it is given, so a Windows path
119
+ // through Git Bash's tar (`-C C:\Users\anton`) names a folder that is not there - `\a` a bell.
120
+ const exported = spawnSync("bash", ["-o", "pipefail", "-c", 'git --git-dir "$1" archive --format=tar "$2" | tar -x -f -', "export", slashed(join(moduleDir, HISTORY_DIR)), `${commit}:code`], { encoding: "utf8", cwd: dir });
119
121
  if (exported.status !== 0)
120
122
  throw new Error(`Could not export ${entry.moduleName}'s code at ${commit.slice(0, 8)}: ${(exported.stderr ?? "").trim()}`);
121
123
  for (const file of [RECORD_FILE, NOTES_FILE])
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync, rmSync, statSync } from "node:fs";
2
- import { basename, dirname, join, relative, resolve } from "node:path";
2
+ import { basename, dirname, join, posix, relative, resolve } from "node:path";
3
3
  import { plainFileParser, withParseCache } from "../plain/parser.js";
4
4
  import { STDLIB_ROOT } from "../plain/stdlib.js";
5
5
  import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS, TEST_PLAIN_FILES, TEST_REQUIREMENTS } from "../plain/spec.js";
@@ -23,7 +23,7 @@ import { describeSpecDiff, renderSpecDiff, specFilesOf } from "./regenerate.js";
23
23
  import { locateDiffLines } from "./diff-view.js";
24
24
  import { agentChanges, changeDiffInFiles } from "./change-view.js";
25
25
  import { createSteering, MAX_STEERS, markTold, steer, waitingSteer } from "./steering.js";
26
- import { projectDirOf } from "./paths.js";
26
+ import { isWithin, projectDirOf, slashed } from "./paths.js";
27
27
  import { changesBetween, parseTree, serializeTree } from "./spec-steps.js";
28
28
  import { hasFiles } from "./testing.js";
29
29
  import { makeRenames, pureRenames, renameText } from "./renames.js";
@@ -523,7 +523,7 @@ export function createWorkLoop(options) {
523
523
  const plan = async (state, spec, from, track = "code") => {
524
524
  const tip = tipEntry(state);
525
525
  const current = track === "code" ? codeTree(spec.tree) : conformanceOf(state, spec, from);
526
- const specFile = relative(options.cwd, tip.plainFile);
526
+ const specFile = slashed(relative(options.cwd, tip.plainFile));
527
527
  let specText = "";
528
528
  try {
529
529
  specText = readFileSync(tip.plainFile, "utf8");
@@ -586,7 +586,7 @@ export function createWorkLoop(options) {
586
586
  const steering = conformance ? undefined : createSteering(planned.step.tree, tip.moduleName);
587
587
  // Shown as its agent is given it: the job's own items, from whichever file they are written in - its imports too, and
588
588
  // for the conformance tests the test plain files of the functional specs whose scenarios it carries out.
589
- const moduleFile = relative(projectDirOf(tip.plainFile), tip.plainFile) || basename(tip.plainFile);
589
+ const moduleFile = slashed(relative(projectDirOf(tip.plainFile), tip.plainFile)) || basename(tip.plainFile);
590
590
  const shown = changeDiffInFiles(agentChanges(planned.step.changes, planned.track), moduleFile, (diff) => whereInFiles(diff, state.chain), conformance ? { module: tip.moduleName, pathOf: testPlainPathOf(spec.tree, tip.moduleName, tip.plainFile, dirname(moduleFile)) } : undefined);
591
591
  const job = options.registry.start({
592
592
  kind: conformance ? "conformance" : "regenerate",
@@ -1779,10 +1779,11 @@ const NO_PLAN = "the planner found no way to cut the work into pulses that hold
1779
1779
  */
1780
1780
  function testPlainPathOf(tree, moduleName, plainFile, base) {
1781
1781
  const bound = Object.entries(tree[TEST_PLAIN_FILES] ?? {});
1782
- const fallback = relative(dirname(plainFile), testDirOf(plainFile));
1782
+ // Named as the parser names a test plain file, with `/`: the names go into a diff, beside the parser's.
1783
+ const fallback = slashed(relative(dirname(plainFile), testDirOf(plainFile)));
1783
1784
  return (funcId, module = moduleName) => {
1784
- const name = bound.find(([, binding]) => binding.module === module && binding.func_id === funcId)?.[0] ?? join(fallback, module, `${funcId}.plain`);
1785
- return join(base, name);
1785
+ const name = bound.find(([, binding]) => binding.module === module && binding.func_id === funcId)?.[0] ?? posix.join(fallback, module, `${funcId}.plain`);
1786
+ return posix.join(base, name);
1786
1787
  };
1787
1788
  }
1788
1789
  /** A diff's lines placed in the .plain files of a chain - the tip's first - named as they are from the project. */
@@ -1791,7 +1792,7 @@ function whereInFiles(diff, chain) {
1791
1792
  // The test plain files too: a conformance pulse's diff has their lines.
1792
1793
  const files = [...chain].reverse().flatMap((entry) => [...specFilesOf(entry.plainFile), ...testPlainFilesOf(entry.plainFile)]);
1793
1794
  // A standard library template by its import path, not by where turri happens to be.
1794
- const nameOf = (path) => (path.startsWith(`${STDLIB_ROOT}/stdlib/`) ? relative(STDLIB_ROOT, path) : relative(projectDirOf(chain.at(-1).plainFile), path) || basename(path));
1795
+ const nameOf = (path) => slashed(isWithin(path, join(STDLIB_ROOT, "stdlib")) ? relative(STDLIB_ROOT, path) : relative(projectDirOf(chain.at(-1).plainFile), path) || basename(path));
1795
1796
  const unique = [...new Set(files)].map((path) => ({ name: nameOf(path), text: readFileSync(path, "utf8") }));
1796
1797
  return locateDiffLines(diff, unique);
1797
1798
  }
@@ -18,6 +18,18 @@ export declare const STDLIB_DIR: string;
18
18
  * codebase instead of living in a scratch directory that can be cleared without anyone
19
19
  * noticing the specs and the code have drifted apart.
20
20
  */
21
+ /**
22
+ * Whether `path` is `root` or inside it, in this machine's paths: on Windows a path is not under `C:\x` by starting
23
+ * with `C:\x/`, and one on another drive is outside whatever its text.
24
+ */
25
+ export declare function isWithin(path: string, root: string): boolean;
26
+ /**
27
+ * A path written with `/` on every machine. A relative one is a name, as git and ***plain write one: shown, compared or
28
+ * put in a diff - a file of a codebase, a .plain file from the project. An absolute one is a path handed to bash, which
29
+ * on Windows is Git Bash, whose tools may read a backslash as an escape: Windows and Git Bash both take `C:/Users`.
30
+ * Opening a file in turri still goes through `join`.
31
+ */
32
+ export declare function slashed(path: string): string;
21
33
  export declare const MODULES_DIR = "plain_modules";
22
34
  export declare function moduleDir(moduleName: string, cwd?: string): string;
23
35
  /** Implementation and unit tests: `plain_modules/<module>/code`. */
@@ -1,5 +1,5 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname, join, resolve, sep } from "node:path";
2
+ import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  /** A module's code record and its tests' - `code/.turri.json`, `tests/.turri.json` (records.ts). */
5
5
  export const RECORD_FILE = ".turri.json";
@@ -21,6 +21,23 @@ export const STDLIB_DIR = join(dirname(dirname(dirname(fileURLToPath(import.meta
21
21
  * codebase instead of living in a scratch directory that can be cleared without anyone
22
22
  * noticing the specs and the code have drifted apart.
23
23
  */
24
+ /**
25
+ * Whether `path` is `root` or inside it, in this machine's paths: on Windows a path is not under `C:\x` by starting
26
+ * with `C:\x/`, and one on another drive is outside whatever its text.
27
+ */
28
+ export function isWithin(path, root) {
29
+ const from = relative(root, path);
30
+ return from === "" || (from !== ".." && !from.startsWith(`..${sep}`) && !isAbsolute(from));
31
+ }
32
+ /**
33
+ * A path written with `/` on every machine. A relative one is a name, as git and ***plain write one: shown, compared or
34
+ * put in a diff - a file of a codebase, a .plain file from the project. An absolute one is a path handed to bash, which
35
+ * on Windows is Git Bash, whose tools may read a backslash as an escape: Windows and Git Bash both take `C:/Users`.
36
+ * Opening a file in turri still goes through `join`.
37
+ */
38
+ export function slashed(path) {
39
+ return sep === "/" ? path : path.split(sep).join("/");
40
+ }
24
41
  export const MODULES_DIR = "plain_modules";
25
42
  export function moduleDir(moduleName, cwd = process.cwd()) {
26
43
  return join(cwd, MODULES_DIR, moduleName);
@@ -168,6 +185,6 @@ export function resolveTemplateDirs(plainFile, extra = []) {
168
185
  dirs.push(...extra.map((dir) => resolve(dir)));
169
186
  const fromEnv = process.env.PLAIN_TEMPLATE_DIRS;
170
187
  if (fromEnv)
171
- dirs.push(...fromEnv.split(":").filter(Boolean).map((dir) => resolve(dir)));
188
+ dirs.push(...fromEnv.split(delimiter).filter(Boolean).map((dir) => resolve(dir)));
172
189
  return [...new Set(dirs)];
173
190
  }
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { relative, resolve, sep } from "node:path";
2
+ import { relative, resolve } from "node:path";
3
+ import { isWithin } from "./paths.js";
3
4
  import { defineTool } from "@earendil-works/pi-coding-agent";
4
5
  import { Type } from "typebox";
5
6
  import { workDiff } from "./lineage.js";
@@ -71,7 +72,7 @@ export function createCanItFailTool(options) {
71
72
  if (left <= 0)
72
73
  return say("can_it_fail has no runs left in this session: decide with what it showed.");
73
74
  const path = resolve(options.buildDir, file);
74
- if (relative(options.buildDir, path).startsWith(`..${sep}`) || relative(options.buildDir, path) === "..")
75
+ if (!isWithin(path, options.buildDir))
75
76
  return say(`${file} is not in the code folder.`);
76
77
  let text;
77
78
  try {
@@ -7,7 +7,7 @@ import { testPlainFilesOf } from "../test-plain-files.js";
7
7
  import { STDLIB_ROOT } from "../plain/stdlib.js";
8
8
  import { conformanceDirFor } from "./conformance.js";
9
9
  import { chainSpec } from "./loop.js";
10
- import { modulesRoot, projectDirOf } from "./paths.js";
10
+ import { isWithin, modulesRoot, projectDirOf, slashed } from "./paths.js";
11
11
  import { HISTORY_DIR } from "./lineage.js";
12
12
  import { codeTree, hasScenarios, marksTestsAgain, readRecord, RECORD_FILE } from "./records.js";
13
13
  import { pureRenames } from "./renames.js";
@@ -167,8 +167,8 @@ function keyed(items) {
167
167
  }
168
168
  /** A spec file as the map names it: a template of turri's standard library by its import path, others from the project. */
169
169
  export function importLabel(path, projectDir, stdlibRoot = STDLIB_ROOT) {
170
- const name = path.startsWith(`${stdlibRoot}/stdlib/`) ? relative(stdlibRoot, path) : relative(projectDir, path) || basename(path);
171
- return name.replace(/\.plain$/, "");
170
+ const name = isWithin(path, join(stdlibRoot, "stdlib")) ? relative(stdlibRoot, path) : relative(projectDir, path) || basename(path);
171
+ return slashed(name).replace(/\.plain$/, "");
172
172
  }
173
173
  /**
174
174
  * The items laid out as the files have them: the module's own file first - its sections in its order, its definitions
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
2
2
  import { createHash } from "node:crypto";
3
3
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
- import { dirname, join } from "node:path";
5
+ import { dirname, join, posix } from "node:path";
6
6
  import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, DEFINITIONS, FUNCTIONAL_REQUIREMENTS, NON_FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS, TEST_REQUIREMENTS, getInheritedFunctionalSpecs, } from "../plain/spec.js";
7
7
  import { validateConcepts } from "../plain/concepts.js";
8
8
  import { sectionTag } from "./prompt.js";
@@ -638,12 +638,12 @@ export function diffRequiredSpecs(before, after, file = "spec.plain") {
638
638
  };
639
639
  const was = byModule(before);
640
640
  const now = byModule(after);
641
- const folder = dirname(file);
641
+ const folder = posix.dirname(file);
642
642
  return [...new Set([...was.keys(), ...now.keys()])]
643
643
  .map((module) => {
644
644
  const text = (items) => (items === undefined ? "" : `***${FUNCTIONAL_REQUIREMENTS}***\n\n${items.join("\n\n")}\n`);
645
645
  const [from, to] = [text(was.get(module)), text(now.get(module))];
646
- const path = folder === "." ? `${module}.plain` : `${folder}/${module}.plain`;
646
+ const path = posix.join(folder, `${module}.plain`);
647
647
  return from === to ? "" : gitDiff(from, to, 3, [path, path]);
648
648
  })
649
649
  .join("");
@@ -128,6 +128,12 @@ export declare function setScriptTimeoutForTests(ms: number | undefined): void;
128
128
  */
129
129
  /** Whether the testing scripts run on the code in `buildDir` itself, not on a copy of it. */
130
130
  export declare function scriptsRunInPlace(buildDir: string): boolean;
131
+ /**
132
+ * The command a testing script runs by: `bash <script> <args>`, every path quoted and written with `/`. On Windows bash is
133
+ * Git Bash, whose tools may read a backslash as an escape - GNU tar reads the `\a` of `C:\Users\anton` as a bell - while
134
+ * Windows and Git Bash both take `C:/Users/anton`.
135
+ */
136
+ export declare function scriptCommand(script: string, args: string[]): string;
131
137
  /**
132
138
  * The harness's run of the unit testing script on the code as it is now - and run_unit_tests'.
133
139
  *
@@ -1,11 +1,11 @@
1
1
  import { fixMethod } from "./prompt.js";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { accessSync, constants, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
4
- import { basename, delimiter, dirname, join, resolve, sep } from "node:path";
4
+ import { basename, delimiter, dirname, join, posix, relative, resolve, sep } from "node:path";
5
5
  import { CONFIG_FILE, CONFIG_KEYS, configModuleFor, configModuleOf, configModulePinned, moduleConfigFile, moduleConfigFileIn, moduleConfigsOf, projectConfigFile, readProjectConfig } from "../config.js";
6
6
  import { reportActivity, reportLogNote, reportNote } from "./activity.js";
7
7
  import { record, signatureHash } from "./ledger.js";
8
- import { ensureInModulesScratch, modulesScratchDir } from "./paths.js";
8
+ import { ensureInModulesScratch, isWithin, modulesScratchDir, slashed } from "./paths.js";
9
9
  import { defineTool } from "@earendil-works/pi-coding-agent";
10
10
  import { Type } from "typebox";
11
11
  import { keepTestOutput, listFiles, shownTestOutput } from "./testing.js";
@@ -300,7 +300,7 @@ function stageTests(testsDirs, target) {
300
300
  let name = file;
301
301
  if (taken.has(name)) {
302
302
  const renamed = `${index + 1}_${basename(file)}`;
303
- name = dirname(file) === "." ? renamed : join(dirname(file), renamed);
303
+ name = posix.dirname(file) === "." ? renamed : posix.join(posix.dirname(file), renamed);
304
304
  }
305
305
  taken.add(name);
306
306
  mkdirSync(dirname(join(target, name)), { recursive: true });
@@ -312,7 +312,7 @@ function stageTests(testsDirs, target) {
312
312
  /** What the project calls a script: its path from the spec's folder when it is under it. */
313
313
  function shown(script) {
314
314
  const parent = dirname(dirname(script));
315
- return script.startsWith(`${parent}/`) ? script.slice(parent.length + 1) : basename(script);
315
+ return isWithin(script, parent) ? relative(parent, script) : basename(script);
316
316
  }
317
317
  /** How long a test run may take: the command time limit. Over it, the run counts as failed. */
318
318
  let scriptTimeoutMs = COMMAND_TIMEOUT_MS;
@@ -352,7 +352,7 @@ async function runScript(cwd, script, args, logDir, options = {}) {
352
352
  const started = Date.now();
353
353
  // Where and how it runs, for the log: how it ended is what the activity says.
354
354
  reportLogNote(` ▶ ${shown(script)} on this machine, ${options.named !== undefined ? "on a fresh copy of the code" : `in place, from ${cwd}`} (limit ${Math.round(timeoutMs / 1000)}s)`);
355
- const { exitCode, output, timedOut } = await runCommand(`bash ${[options.named ?? script, ...args].map(quote).join(" ")}`, {
355
+ const { exitCode, output, timedOut } = await runCommand(scriptCommand(options.named ?? script, args), {
356
356
  cwd,
357
357
  env: scriptEnv(),
358
358
  timeoutMs,
@@ -419,6 +419,14 @@ function withScriptLineNote(output, script) {
419
419
  });
420
420
  return `${[...new Set(notes)].join("\n")}\n\n${output}`;
421
421
  }
422
+ /**
423
+ * The command a testing script runs by: `bash <script> <args>`, every path quoted and written with `/`. On Windows bash is
424
+ * Git Bash, whose tools may read a backslash as an escape - GNU tar reads the `\a` of `C:\Users\anton` as a bell - while
425
+ * Windows and Git Bash both take `C:/Users/anton`.
426
+ */
427
+ export function scriptCommand(script, args) {
428
+ return `bash ${[script, ...args].map((path) => quote(slashed(path))).join(" ")}`;
429
+ }
422
430
  /** A path, quoted for bash. */
423
431
  function quote(path) {
424
432
  return `'${path.replace(/'/g, "'\\''")}'`;
@@ -5,7 +5,7 @@ import { Type } from "typebox";
5
5
  import { reportActivity } from "./activity.js";
6
6
  import { maskSecrets } from "./masking.js";
7
7
  import { NOTES_FILE } from "./notes.js";
8
- import { modulesScratchDir } from "./paths.js";
8
+ import { modulesScratchDir, slashed } from "./paths.js";
9
9
  import { BASE_RECORD_FILE, RECORD_FILE } from "./paths.js";
10
10
  import { missingToolchain, runUnitScript, scriptFailure } from "./test-scripts.js";
11
11
  import { COMMAND_TIMEOUT_MS } from "./shell.js";
@@ -239,7 +239,7 @@ export function listFiles(root) {
239
239
  if (statSync(full).isDirectory())
240
240
  walk(full);
241
241
  else
242
- found.push(relative(root, full));
242
+ found.push(slashed(relative(root, full)));
243
243
  }
244
244
  };
245
245
  if (existsSync(root))
@@ -35,7 +35,7 @@ for every functional spec's scenarios.
35
35
  --report <file.json> write a report of the run there - outcome, usage, pulses, functional specs completed -
36
36
  as it starts, as each pulse ends and as it exits (docs/headless.md)
37
37
 
38
- PLAIN_TEMPLATE_DIRS colon-separated template directories`;
38
+ PLAIN_TEMPLATE_DIRS template directories, separated as PATH is (: or ; on Windows)`;
39
39
  const { positional, options } = parseArgs(process.argv.slice(2), ["--dry-run", "--start-over", "--from-scratch", "--from-scratch-chain"], USAGE, ["--build-dir", "--report", "--harness-model", "--judge-model", "--review", "--mutation-testing"]);
40
40
  const { report, buildDir } = headlessOptions(options);
41
41
  const named = positional[0] ?? readProjectConfig(process.cwd()).module;
package/dist/skill.js CHANGED
@@ -49,7 +49,7 @@ export function loadSkill(skillDir) {
49
49
  const name = String(data.name ?? "");
50
50
  const description = String(data.description ?? "");
51
51
  if (!name || !description) {
52
- throw new Error(`${dir}/SKILL.md: 'name' and 'description' are required by the Agent Skills spec`);
52
+ throw new Error(`${join(dir, "SKILL.md")}: 'name' and 'description' are required by the Agent Skills spec`);
53
53
  }
54
54
  const rawGates = data.metadata?.gates ?? [];
55
55
  const gatesByStep = new Map();
@@ -3,7 +3,7 @@ import { basename, dirname, join, relative, resolve, sep } from "node:path";
3
3
  import { DEFAULT_TEST_DIR, testDirOf } from "./config.js";
4
4
  import { PLAIN_SOURCE_FILE_EXTENSION } from "./plain/parser.js";
5
5
  import { FUNC_ID_KEY, loadFrontmatter, MODULE_KEY } from "./plain/test-plain-file.js";
6
- import { isProjectDir, projectDirOf } from "./regenerate/paths.js";
6
+ import { isProjectDir, isWithin, projectDirOf } from "./regenerate/paths.js";
7
7
  /**
8
8
  * Where a project's test plain files are, and what each belongs to: `<test-dir>/<module>/`, every `.plain` file in it
9
9
  * a test plain file of that module - its functional specs' conformance and acceptance scenarios. turri finds modules
@@ -40,11 +40,6 @@ function plainFilesUnder(dir) {
40
40
  export function testPlainFilesOf(plainFile) {
41
41
  return plainFilesUnder(join(testDirOf(plainFile), basename(plainFile, PLAIN_SOURCE_FILE_EXTENSION)));
42
42
  }
43
- /** Whether a path is a folder, or below one. */
44
- function within(path, folder) {
45
- const from = relative(folder, path);
46
- return from === "" || (!from.startsWith("..") && !from.startsWith(sep) && from !== "..");
47
- }
48
43
  /** The frontmatter of a .plain file, as a test plain file's is read; empty when it cannot be read. */
49
44
  function frontmatterOf(path) {
50
45
  try {
@@ -81,9 +76,9 @@ export function testPlaceOf(path) {
81
76
  const testDir = testDirOf(join(projectDir, "x.plain"));
82
77
  const metadata = directory || !existsSync(absolute) ? {} : frontmatterOf(absolute);
83
78
  const bound = typeof metadata[MODULE_KEY] === "string" && typeof metadata[FUNC_ID_KEY] === "string";
84
- if (!within(absolute, testDir) && !bound)
79
+ if (!isWithin(absolute, testDir) && !bound)
85
80
  return undefined;
86
- const parts = within(absolute, testDir) ? relative(testDir, absolute).split(sep).filter(Boolean) : [];
81
+ const parts = isWithin(absolute, testDir) ? relative(testDir, absolute).split(sep).filter(Boolean) : [];
87
82
  const folderModule = directory ? parts[0] : parts.length > 1 ? parts[0] : undefined;
88
83
  return {
89
84
  projectDir,
@@ -151,7 +146,7 @@ export function strayTestPlainFiles(projectDir) {
151
146
  const folder = relative(testDir, dirname(path)).split(sep).filter(Boolean)[0];
152
147
  const metadata = frontmatterOf(path);
153
148
  const named = typeof metadata[MODULE_KEY] === "string" ? metadata[MODULE_KEY] : undefined;
154
- const home = (module) => `${shown(join(testDir, module), projectDir)}/`;
149
+ const home = (module) => `${shown(join(testDir, module), projectDir)}${sep}`;
155
150
  if (folder === undefined) {
156
151
  strays.push({ file, problem: named === undefined ? "move it to the folder of its module, in the test folder" : `move it to ${home(named)} (its module: ${named})` });
157
152
  }
package/dist/tools.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { mkdirSync, writeFileSync } from "node:fs";
2
- import { dirname, relative, resolve } from "node:path";
2
+ import { dirname, resolve } from "node:path";
3
+ import { isWithin } from "./regenerate/paths.js";
3
4
  import { defineTool } from "@earendil-works/pi-coding-agent";
4
5
  import { Type } from "typebox";
5
6
  /**
@@ -24,7 +25,7 @@ export function createWriteArtifactTool(runDir) {
24
25
  }),
25
26
  async execute(_id, params) {
26
27
  const target = resolve(root, params.path);
27
- if (relative(root, target).startsWith("..")) {
28
+ if (!isWithin(target, root)) {
28
29
  throw new Error(`write_artifact: '${params.path}' escapes the artifact directory`);
29
30
  }
30
31
  mkdirSync(dirname(target), { recursive: true });
@@ -1,6 +1,6 @@
1
1
  # Installation
2
2
 
3
- **turri** runs wherever [pi](https://pi.dev) runs - macOS, Linux, WSL - with git, bash and Node 22.19 or newer (a Linux distribution's own `nodejs` package is often older: take it from nodejs.org, nvm or NodeSource). Native Windows is best effort: it needs bash on the PATH (Git for Windows' Git Bash), and has no OS sandbox under the agents' commands.
3
+ **turri** runs wherever [pi](https://pi.dev) runs - macOS, Linux and Windows, natively or in WSL - with git, bash and Node 22.19 or newer (a Linux distribution's own `nodejs` package is often older: take it from nodejs.org, nvm or NodeSource). On Windows the bash is Git for Windows' Git Bash, on the PATH; native Windows has no OS sandbox under the agents' commands, the command check and the audit holding alone.
4
4
 
5
5
  The agents' commands run on this machine, with its toolchains - see [the sandbox](sandbox.md). Each is checked before it runs and audited after, on every platform; under them an OS sandbox fences it where the OS has one: Seatbelt on macOS, always there, and bubblewrap on Linux and WSL 2 - `apt install bubblewrap`, or your distribution's package.
6
6
 
@@ -133,6 +133,6 @@ For Gemini, `GEMINI_API_KEY` is what makes [pi](https://pi.dev) *offer* the goog
133
133
 
134
134
  | variable | |
135
135
  | --- | --- |
136
- | `PLAIN_TEMPLATE_DIRS` | colon-separated template directories, e.g. the standard library |
136
+ | `PLAIN_TEMPLATE_DIRS` | template directories, separated as `PATH` is (`:`, or `;` on Windows), e.g. the standard library |
137
137
  | `TURRI_COMMAND_TIMEOUT` | seconds a command may run before it is stopped - an agent's own, its tests (default `120`) |
138
138
  | `TURRI_LEDGER` | `off`: write no [ledger](using.md#the-ledger) at all, whatever `ledger-keep:` says - the test suite sets it |
@@ -220,6 +220,8 @@ Whether something is done is never the agent's call, and never a command it chos
220
220
  | `test_scripts/run_conformance_tests_<lang>.sh` | `run_conformance_tests_<lang>.sh <build> <tests>` | whether the conformance tests pass - the whole suite in `plain_modules/<module>/tests`, every functionality's and those carried up from below, at once - and the tests' static checks with them, exit 80 when only the checks fail |
221
221
  | `test_scripts/prepare_environment_<lang>.sh` - optional | `prepare_environment_<lang>.sh <build>`, before every run of the conformance testing script | nothing on its own: it readies the environment the conformance tests run in - a `mvn install` of the build, say - and when it fails, the conformance tests are not run and the run fails as the preparation's |
222
222
 
223
+ Each is run by bash, its folders given as absolute paths - on Windows written with forward slashes (`C:/Users/...`), which Windows and Git Bash both take: GNU tar, and the other tools of Git Bash that read a backslash as an escape, would take the `\a` of `C:\Users\anton` for a bell.
224
+
223
225
  The `implement-unit-testing-script` and `implement-conformance-testing-script` skills write them, in the background on the coding model of the module they are for ([background skills](skills-and-gates.md)). While one is being written - in the background, or to its end in print mode - a module built with the config it is named in waits for it, whether it lacks that script or has one being written over (a pulse started meanwhile would run against the old one) - `waiting for its unit testing script, which is being written`, or its conformance testing script - rather than fail for want of it, and is looked at again once the run ends: built, once the script is there, and stopped for want of it as before, when the run wrote none (`src/regenerate/scripts-being-written.ts`). A script written for one module's config file holds only the modules built with that file. They are looked for at the project root - the folder that holds `plain_modules` - in this order:
224
226
 
225
227
  1. `config.turri.yaml` - with the module's own `config.turri.<module>.yaml` over it, or the one of a module it requires - naming them by path from the root:
@@ -1,9 +1,8 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
- # Export Java 21
4
- #export JAVA_HOME="/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home"
5
- #export PATH="$JAVA_HOME/bin:$PATH"
6
- echo "JAVA_HOME: $JAVA_HOME"
3
+ # Java 21: the person's JAVA_HOME, else the java on the PATH - nothing here names where one OS keeps it.
4
+ echo "JAVA_HOME: ${JAVA_HOME:-unset - the java on the PATH}"
5
+ java -version 2>&1
7
6
 
8
7
  # Check if build folder name is provided
9
8
  if [ -z "$1" ]; then
@@ -19,14 +18,13 @@ if [ -z "$2" ]; then
19
18
  exit 1
20
19
  fi
21
20
 
22
- current_dir=$(pwd)
23
-
24
21
  # Resolve the conformance tests folder to an absolute path ($2 may be relative
25
- # on older harnesses; turri passes it as an absolute path).
26
- case "$2" in
27
- /*) CONFORMANCE_TESTS_SOURCE="$2" ;;
28
- *) CONFORMANCE_TESTS_SOURCE="$current_dir/$2" ;;
29
- esac
22
+ # on older harnesses; turri passes it as an absolute path - on Windows C:/Users/...,
23
+ # which a test for a leading / would take for a relative one).
24
+ CONFORMANCE_TESTS_SOURCE="$(cd "$2" 2>/dev/null && pwd)" || {
25
+ printf "Error: the conformance tests folder '%s' does not exist.\n" "$2"
26
+ exit 2
27
+ }
30
28
 
31
29
  # Host-relative paths of the module, as declared in ***implementation reqs***.
32
30
  # Replace the placeholders with the module's integration source path and its
@@ -104,11 +102,11 @@ else
104
102
  printf "Current directory: $(pwd)\n"
105
103
 
106
104
  printf "Subfolder does not exist. Creating it...\n"
107
- mkdir -p $CONFORMANCE_TESTS_FOLDER
105
+ mkdir -p "$CONFORMANCE_TESTS_FOLDER"
108
106
  fi
109
107
 
110
108
  printf "Copying all files and folders from $CONFORMANCE_TESTS_SOURCE to $CONFORMANCE_TESTS_FOLDER...\n"
111
- cp -R "$CONFORMANCE_TESTS_SOURCE"/* $CONFORMANCE_TESTS_FOLDER
109
+ cp -R "$CONFORMANCE_TESTS_SOURCE"/* "$CONFORMANCE_TESTS_FOLDER"
112
110
 
113
111
  # Move to the subfolder
114
112
  printf "Moving to $CONFORMANCE_TESTS_FOLDER...\n"
@@ -1,9 +1,8 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
- # Export Java 21
4
- #export JAVA_HOME="/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home"
5
- #export PATH="$JAVA_HOME/bin:$PATH"
6
- echo "JAVA_HOME: $JAVA_HOME"
3
+ # Java 21: the person's JAVA_HOME, else the java on the PATH - nothing here names where one OS keeps it.
4
+ echo "JAVA_HOME: ${JAVA_HOME:-unset - the java on the PATH}"
5
+ java -version 2>&1
7
6
 
8
7
  # Check if subfolder name is provided
9
8
  if [ -z "$1" ]; then
@@ -25,15 +24,15 @@ if [ ! -d "$MAIN_PROJECT_FOLDER" ]; then
25
24
  fi
26
25
 
27
26
  # clean existing code from the main project folder
28
- rm -rf $MAIN_PROJECT_FOLDER/<placeholder for integration code>/*
29
- rm -rf $MAIN_PROJECT_FOLDER/<placeholder for integration code tests>/*
27
+ rm -rf "$MAIN_PROJECT_FOLDER/<placeholder for integration code>"/*
28
+ rm -rf "$MAIN_PROJECT_FOLDER/<placeholder for integration code tests>"/*
30
29
 
31
30
  # copy generated code to the main project folder
32
31
  # FIX: added the mkdir lines otherwise it complains that the cp destintation directory does not exist
33
- mkdir -p $MAIN_PROJECT_FOLDER/<placeholder for integration code>
34
- mkdir -p $MAIN_PROJECT_FOLDER/<placeholder for integration code tests>
35
- cp -R $1/<placeholder for integration code>/* $MAIN_PROJECT_FOLDER/<placeholder for integration code>
36
- cp -R $1/<placeholder for integration code tests>/* $MAIN_PROJECT_FOLDER/<placeholder for integration code tests>
32
+ mkdir -p "$MAIN_PROJECT_FOLDER/<placeholder for integration code>"
33
+ mkdir -p "$MAIN_PROJECT_FOLDER/<placeholder for integration code tests>"
34
+ cp -R "$1/<placeholder for integration code>"/* "$MAIN_PROJECT_FOLDER/<placeholder for integration code>"
35
+ cp -R "$1/<placeholder for integration code tests>"/* "$MAIN_PROJECT_FOLDER/<placeholder for integration code tests>"
37
36
 
38
37
  # Move to the subfolder
39
38
  # FIX: added this line to print the current directory to help the LLM
@@ -124,15 +124,15 @@ output=$(mvn test --no-transfer-progress 2>&1)
124
124
 
125
125
  Both scripts are invoked by turri with positional arguments, on the person's machine. They MUST:
126
126
 
127
- 1. **Be POSIX-bash (`.sh`) on macOS / Linux, PowerShell (`.ps1`) on Windows.** Executable, idempotent — re-running with the same inputs produces the same result
127
+ 1. **Be Bash (`.sh`) on every OS.** turri runs only `.sh` scripts, with the `bash` on the person's PATH - macOS's own bash 3.2, Linux's, Git Bash on Windows - so the script keeps to what all three have (the testing-script skills' *Bash specifics* list it). A PowerShell (`.ps1`) copy is only for a person running it by hand. Executable, idempotent — re-running with the same inputs produces the same result
128
128
  2. **Validate every positional argument up front.** Exit with a clear `Usage:` line on bad args. Conventional exit codes (consistent with the shared testing-script rules):
129
129
  - `1` — bad arguments / usage error (and "no tests discovered" for the conformance runner)
130
130
  - `2` — missing or inaccessible input folder
131
131
  - `69` — unrecoverable environment failure (missing toolchain, cannot enter working folder, install failed)
132
132
  - Any other non-zero code — propagated verbatim from the underlying build / test tool
133
133
 
134
- turri passes `$1` (and `$2` for the conformance runner) as **absolute paths** (older harnesses passed relative ones). Never build a derived path by concatenating a raw argument (`.tmp/$1`, `<lang>_$1`, `$current_dir/$2`) — with an absolute argument that produces a doubled path (`/project//abs/path/...`). Use the argument as-is where a path is needed, take its `basename` when naming a scratch folder, and resolve `$2` to absolute (if it isn't already) before any `cd`
135
- 3. **Echo the toolchain home at the top** — the first thing a developer checks when CI breaks. For Java: `JAVA_HOME`. For Python: the active interpreter (`python --version` / `which python`). For Node: `node --version`. For Go: `go env GOROOT`. Pick the variable whose value most often explains "why does it work locally but not on the CI runner?"
134
+ turri passes `$1` (and `$2` for the conformance runner) as **absolute paths** (older harnesses passed relative ones). Never build a derived path by concatenating a raw argument (`.tmp/$1`, `<lang>_$1`, `$current_dir/$2`) — with an absolute argument that produces a doubled path (`/project//abs/path/...`). Use the argument as-is where a path is needed, take its `basename` when naming a scratch folder, and resolve `$2` to absolute with `$(cd "$2" && pwd)` before any `cd` - never by testing for a leading `/`, as on Windows turri passes `C:/Users/...`. Quote every path: a Windows home has spaces in it
135
+ 3. **Echo the toolchain home at the top** — the first thing a developer checks when CI breaks. For Java: `JAVA_HOME`. For Python: the active interpreter (`python --version` / `command -v python`). For Node: `node --version`. For Go: `go env GOROOT`. Pick the variable whose value most often explains "why does it work locally but not on the CI runner?"
136
136
  4. **Respect `VERBOSE=1`.** Gate chatty diagnostic prints behind `if [ "${VERBOSE:-}" = "1" ]` (and the PowerShell equivalent). Errors and key step markers print unconditionally
137
137
  5. **Resolve paths relative to the script, not `$PWD`.** Use `"$(cd "$(dirname "$0")/<relative-path-to-anchor>" && pwd)"`. Hard-coded `../../` chains break the moment turri's `cwd` changes
138
138
  6. **Create destination directories before copying.** `mkdir -p` before any `cp -R` / `rsync` / `robocopy` — most copy commands do not create intermediate directories and fail silently in some shells
@@ -266,7 +266,7 @@ Use them as a template when adding a new embedded integration in Java / Maven
266
266
 
267
267
  1. Copy the two scripts from a working embedded-integration module into the project's `test_scripts/`
268
268
  2. Search-and-replace the package segment everywhere it appears — including the test-filter argument (the most commonly missed spot)
269
- 3. `chmod +x` both (and verify ACLs on Windows for the `.ps1` siblings)
269
+ 3. `chmod +x` both (Git Bash on Windows needs nothing; verify ACLs only for `.ps1` copies)
270
270
  4. Do not link them from the ***plain: turri finds them in the project root - `config.turri.yaml` (`unittests-script:`, `conformance-tests-script:`), else the one of each kind in the root, else in `test_scripts/` - and shows them to the agents itself. If `test_scripts/` ends up with two scripts of one kind, name the one to use in `config.turri.yaml`.
271
271
  5. Smoke-test by running each script manually with the build output folder as `$1` (and the conformance-tests folder as `$2` for the conformance runner). Confirm exit codes match what turri expects
272
272
 
@@ -38,7 +38,7 @@ turri (not the agent that writes the tests) runs the script once per check, agai
38
38
  bash run_conformance_tests_<lang>.sh <build_folder> <conformance_tests_folder>
39
39
  ```
40
40
 
41
- Both arguments are absolute paths: `<build_folder>` is the module's generated code (`plain_modules/<module>/code`), and `<conformance_tests_folder>` is the folder holding the whole suite. The harness runs the script on the person's machine - macOS, Linux or WSL, with its toolchains, in the person's own environment - and its exit code alone decides whether the conformance tests pass.
41
+ Both arguments are absolute paths (on Windows written with forward slashes, `C:/Users/...`): `<build_folder>` is the module's generated code (`plain_modules/<module>/code`), and `<conformance_tests_folder>` is the folder holding the whole suite. The harness runs the script on the person's machine - macOS, Linux or Windows, where bash is Git Bash - with its toolchains, in the person's own environment - and its exit code alone decides whether the conformance tests pass.
42
42
 
43
43
  Every conformance script is self-contained: toolchain check, argument validation, stage the build into `<temp>/<lang>_<basename of $1>`, install dependencies there in isolation, check the tests in `$2` statically, run the suite in `$2` against it, clean up on exit. Nothing is prepared ahead of time by another script - unless the project already has a `prepare_environment*.sh` (a prepare script the project brought, or one `prepare-environment-script:` names): turri runs it on the same build before every run of the conformance script, so keep it, and let the conformance script rely on what it sets up rather than doing it again. Never write a prepare script yourself.
44
44
 
@@ -53,16 +53,16 @@ Everything else — toolchain check, build staging, dependency isolation, exit c
53
53
 
54
54
  ## Pick the Shell
55
55
 
56
- The harness runs only Bash (`.sh`) scripts, on macOS, Linux and WSL alike. Always write `run_conformance_tests_<lang>.sh`, and make it work on all of them.
56
+ The harness runs only Bash (`.sh`) scripts, on macOS, Linux and Windows (Git Bash) alike. Always write `run_conformance_tests_<lang>.sh`, and make it work on all of them - see [Bash specifics](#bash-specifics).
57
57
 
58
- A PowerShell (`.ps1`) copy is optional and only for people who run the script by hand on native Windows; the harness never runs it. Write one only if the user asks for it. The same pattern applies to both — only the syntax changes.
58
+ A PowerShell (`.ps1`) copy is optional and only for people who run the script by hand in PowerShell; the harness never runs it. Write one only if the user asks for it. The same pattern applies to both — only the syntax changes.
59
59
 
60
60
  ## The Pattern
61
61
 
62
62
  1. **Toolchain check.** Verify that the required language runtime / build tool (and the required version, if any) is installed. If not, print an error and exit with code `69`.
63
63
  2. **Argument validation.** Require **two** positional arguments: `<build_folder>` and `<conformance_tests_folder>`. If either is missing, print usage and exit with code `69`.
64
64
  3. **Resolve the conformance tests folder to an absolute path.** turri passes `$2` as an absolute path; older harnesses passed it relative to the invocation directory. Resolve it once, up front, into a variable the test command in step 8 uses:
65
- - Bash: `case "$2" in /*) CONFORMANCE_TESTS_FOLDER="$2" ;; *) CONFORMANCE_TESTS_FOLDER="$(pwd)/$2" ;; esac`
65
+ - Bash: `CONFORMANCE_TESTS_FOLDER="$(cd "$2" && pwd)" || exit 2` - not a test for a leading `/`, which takes Windows' `C:/Users/...` for a relative path
66
66
  - PowerShell: `if (-not [System.IO.Path]::IsPathRooted($ConformanceTestsFolder)) { $ConformanceTestsFolder = Join-Path (Get-Location) $ConformanceTestsFolder }`
67
67
 
68
68
  Never concatenate `$current_dir/$2` at the point of use — with an absolute `$2` that produces a doubled path (`/project//abs/path/...`), the classic symptom being `ImportError: Start directory is not importable` pointing at a path that contains the project root twice.
@@ -169,7 +169,7 @@ The dependency environment must live **inside** `$WORKING_FOLDER` so the test ru
169
169
 
170
170
  | Language | Isolation mechanism | Install command (run inside `$WORKING_FOLDER`) | Test command (point at `$CONFORMANCE_TESTS_FOLDER`) |
171
171
  |---|---|---|---|
172
- | Python | `venv` at `./.venv` | `python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt` | `python -m unittest discover -b -s "$CONFORMANCE_TESTS_FOLDER"` (or `pytest "$CONFORMANCE_TESTS_FOLDER"`) |
172
+ | Python | `venv` at `./.venv` | `"$PYTHON" -m venv .venv && "$VENV_BIN/python" -m pip install -r requirements.txt` - `$VENV_BIN` is `.venv/bin`, or `.venv/Scripts` on Windows | `"$VENV_BIN/python" -m unittest discover -b -s "$CONFORMANCE_TESTS_FOLDER"` (or `"$VENV_BIN/pytest" "$CONFORMANCE_TESTS_FOLDER"`) |
173
173
  | Node.js | local `./node_modules` (default) | `npm ci` (preferred) or `npm install` | `npx jest --rootDir "$CONFORMANCE_TESTS_FOLDER"` |
174
174
  | Java | project-scoped Maven repo at `./.m2` | `mvn -Dmaven.repo.local=./.m2 install -DskipTests` (build + install artifact so the test pom can resolve it) | `mvn -f "$CONFORMANCE_TESTS_FOLDER/pom.xml" -Dmaven.repo.local="$(pwd)/.m2" test` |
175
175
  | Go | module cache at `./.gocache` | `GOMODCACHE="$PWD/.gocache" go mod download` (optional pre-warm) | `GOMODCACHE="$PWD/.gocache" go test "$CONFORMANCE_TESTS_FOLDER/..."` |
@@ -181,16 +181,24 @@ Notes:
181
181
  - **Always pass the isolation flag/env var to both the install command and the test command.** They must agree on where deps live, otherwise the test command will silently fall back to the global cache **or** (worse) write into `$1` / `$2`.
182
182
  - **Python is the only ecosystem where the venv is mandatory** to satisfy "into a virtual environment" literally. The others use language-native equivalents that achieve the same isolation.
183
183
  - **Propagate the install exit code immediately.** In Bash: `<install cmd> || exit $?`. In PowerShell: check `$LASTEXITCODE` and `exit $LASTEXITCODE` if non-zero.
184
- - **Time the dependency setup** with `date +%s.%N` (Bash) / `Get-Date` (PowerShell) and print `"Requirements setup completed in X.XX seconds"`.
184
+ - **Time the dependency setup** with bash's own `SECONDS` (`SECONDS=0` before, `$SECONDS` after) / `Get-Date` (PowerShell) and print `"Requirements setup completed in X seconds"`.
185
185
 
186
186
  ### Bash specifics
187
187
 
188
- - **Shebang:** `#!/bin/bash`.
188
+ - **Shebang:** `#!/usr/bin/env bash` - turri runs it with `bash` itself, and a person running it by hand gets the bash on their PATH, which is not at `/bin/bash` everywhere.
189
189
  - **File naming:** `run_conformance_tests_<lang>.sh`, placed in `assets/` (skill reference) or `test_scripts/` (target project).
190
190
  - **Arguments:** `$1` = build folder, `$2` = conformance tests folder.
191
191
  - **Make it executable:** `chmod +x` the produced script.
192
- - **`cd` failure check:** the reference scripts use the `cd ... 2>/dev/null` + `[ $? -ne 0 ]` pattern. Keep it.
193
- - **Portable:** the harness runs the script on macOS and Linux alike. Stick to POSIX tools and flags both have (e.g. `cp -R`, `mktemp`, plain `grep` - not GNU-only or BSD-only flags, not a macOS-only `/usr/libexec/java_home`), and let the toolchain check report clearly when the runtime is missing.
192
+ - **`cd` failure check:** `if ! cd "$DIR" 2>/dev/null; then ...; exit 2; fi`, as the reference scripts do - the failure tested on the `cd` itself, not on a `$?` a later command has already replaced.
193
+ - **Portable - macOS, Linux and Windows alike.** turri runs the script with the `bash` on the person's PATH: on macOS often the system's own bash 3.2, on Windows Git Bash. Write it for all three:
194
+ - bash 3.2's features only - no `mapfile` / `readarray`, `declare -A`, `${var,,}`, `|&`;
195
+ - tools and flags that GNU, BSD and Git Bash all have (`cp -R`, `mktemp -d`, `find`, `grep -E` with `[[:space:]]` rather than `\s`, `sed` without `-i`), and none that only some machines have: not `tree`, `bc`, `jq`, `realpath`, `timeout`, `date +%N` (time with bash's own `SECONDS`), not macOS's `/usr/libexec/java_home` (take `JAVA_HOME`, else the `java` on the PATH);
196
+ - a folder argument resolved with `$(cd "$1" && pwd)`, never told absolute by a leading `/`: on Windows turri passes `C:/Users/...`;
197
+ - every path quoted: a Windows home has spaces in it (`C:/Users/Ana Lee`);
198
+ - a path a native tool reads from a file the script writes - a config, a settings file - relative to the working folder, as Git Bash's `/tmp/...` means nothing to a Windows program reading a file;
199
+ - a Python venv keeps its tools in `.venv/bin`, on Windows in `.venv/Scripts`: pick the one that is there (`if [ -d .venv/Scripts ]; then VENV_BIN=.venv/Scripts; else VENV_BIN=.venv/bin; fi`) and call them by path. And on Windows `python3` may be the Microsoft Store's stand-in, which runs nothing: take the first of `python3` and `python` that runs `-c "import sys"`;
200
+ - LF line endings - bash cannot run a script with CRLF ones, which a Windows checkout under git's `core.autocrlf` makes of it. When the project is a git repository whose `.gitattributes` lacks `*.sh text eol=lf`, say so in your result.
201
+ - a missing runtime reported clearly by the toolchain check, on every one of them.
194
202
 
195
203
  ### PowerShell specifics (by-hand Windows copy only)
196
204
 
@@ -1,6 +1,24 @@
1
- #!/bin/bash
2
- export JAVA_HOME=$(/usr/libexec/java_home -v 21)
3
- java --version
1
+ #!/usr/bin/env bash
2
+
3
+ # Java 21 or newer, and Maven: JAVA_HOME's java when it is set, else the one on the PATH - the same on macOS, Linux
4
+ # and Windows (Git Bash). Not macOS's /usr/libexec/java_home, which no other OS has.
5
+ JAVA="java"
6
+ [ -n "${JAVA_HOME:-}" ] && JAVA="$JAVA_HOME/bin/java"
7
+ if ! "$JAVA" -version >/dev/null 2>&1; then
8
+ echo "Error: Java is not installed (no $JAVA)."
9
+ exit 69
10
+ fi
11
+ JAVA_VERSION="$("$JAVA" -version 2>&1 | sed -n 's/.*version "\([0-9]*\).*/\1/p' | head -n 1)"
12
+ if [ -z "$JAVA_VERSION" ] || [ "$JAVA_VERSION" -lt 21 ]; then
13
+ echo "Error: Java 21 or newer is needed; $JAVA is Java ${JAVA_VERSION:-of a version it does not say}."
14
+ exit 69
15
+ fi
16
+ if ! command -v mvn >/dev/null 2>&1; then
17
+ echo "Error: Maven (mvn) is not installed."
18
+ exit 69
19
+ fi
20
+ "$JAVA" -version
21
+ mvn --version
4
22
 
5
23
  # Check if build folder name is provided
6
24
  if [ -z "$1" ]; then
@@ -21,13 +39,14 @@ printf "Current directory: $current_dir\n"
21
39
 
22
40
  # Resolve the conformance tests folder to an absolute path so it can be used
23
41
  # after changing into the working folder ($2 may be relative to the invocation
24
- # directory on older harnesses; turri passes it as an absolute path).
25
- case "$2" in
26
- /*) CONFORMANCE_TESTS_SOURCE="$2" ;;
27
- *) CONFORMANCE_TESTS_SOURCE="$current_dir/$2" ;;
28
- esac
42
+ # directory on older harnesses; turri passes it as an absolute path - on Windows
43
+ # C:/Users/..., which a test for a leading / would take for a relative one).
44
+ CONFORMANCE_TESTS_SOURCE="$(cd "$2" 2>/dev/null && pwd)" || {
45
+ printf "Error: the conformance tests folder '%s' does not exist.\n" "$2"
46
+ exit 2
47
+ }
29
48
 
30
- tree "$CONFORMANCE_TESTS_SOURCE"
49
+ find "$CONFORMANCE_TESTS_SOURCE" -type f
31
50
 
32
51
  # Working folders live in the system temp directory. $1 and $2 may be absolute
33
52
  # paths, so only their basenames are used to build the working folder names.
@@ -58,13 +77,11 @@ cp -R "$1"/* "$JAVA_BUILD_SUBFOLDER"
58
77
  printf "Copied from $1 to $JAVA_BUILD_SUBFOLDER...\n"
59
78
 
60
79
  # Move to the subfolder
61
- cd "$JAVA_BUILD_SUBFOLDER" 2>/dev/null
62
- printf "Moved to $JAVA_BUILD_SUBFOLDER...\n"
63
-
64
- if [ $? -ne 0 ]; then
80
+ if ! cd "$JAVA_BUILD_SUBFOLDER" 2>/dev/null; then
65
81
  printf "Error: Java build folder '$JAVA_BUILD_SUBFOLDER' does not exist.\n"
66
82
  exit 2
67
83
  fi
84
+ printf "Moved to $JAVA_BUILD_SUBFOLDER...\n"
68
85
 
69
86
  echo "Runinng maven install in $(pwd)..."
70
87
  output=$(mvn clean install -DskipTests 2>&1)
@@ -89,13 +106,11 @@ cp -R "$CONFORMANCE_TESTS_SOURCE"/* "$CONFORMANCE_TESTS_FOLDER"
89
106
  printf "Copied from $CONFORMANCE_TESTS_SOURCE to $CONFORMANCE_TESTS_FOLDER...\n"
90
107
 
91
108
  # Move to the subfolder
92
- cd "$CONFORMANCE_TESTS_FOLDER" 2>/dev/null
93
- printf "Moved to $CONFORMANCE_TESTS_FOLDER...\n"
94
-
95
- if [ $? -ne 0 ]; then
109
+ if ! cd "$CONFORMANCE_TESTS_FOLDER" 2>/dev/null; then
96
110
  printf "Error: Java conformance tests folder '$CONFORMANCE_TESTS_FOLDER' does not exist.\n"
97
111
  exit 2
98
112
  fi
113
+ printf "Moved to $CONFORMANCE_TESTS_FOLDER...\n"
99
114
 
100
115
  echo "Runinng maven install in $(pwd)..."
101
116
  output=$(mvn clean install -DskipTests 2>&1)
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
3
  UNRECOVERABLE_ERROR_EXIT_CODE=69
4
4
 
@@ -16,23 +16,28 @@ if [ -z "$2" ]; then
16
16
  exit $UNRECOVERABLE_ERROR_EXIT_CODE
17
17
  fi
18
18
 
19
- # Try to find Python interpreter (python3 first, then python)
20
- if command -v python3 &> /dev/null; then
21
- PYTHON_CMD="python3"
22
- elif command -v python &> /dev/null; then
23
- PYTHON_CMD="python"
24
- else
19
+ # A Python interpreter that runs: python3 first, then python. Found on the PATH is not enough - on Windows python3 may
20
+ # be the Microsoft Store's stand-in, which runs nothing.
21
+ PYTHON_CMD=""
22
+ for candidate in python3 python; do
23
+ if "$candidate" -c "import sys" >/dev/null 2>&1; then
24
+ PYTHON_CMD="$candidate"
25
+ break
26
+ fi
27
+ done
28
+ if [ -z "$PYTHON_CMD" ]; then
25
29
  printf "Error: Python interpreter not found. Please install Python.\n"
26
30
  exit $UNRECOVERABLE_ERROR_EXIT_CODE
27
31
  fi
28
32
 
29
33
  # Resolve the conformance tests folder to an absolute path so it can be used
30
34
  # after changing into the working folder ($2 may be relative to the invocation
31
- # directory on older harnesses; turri passes it as an absolute path).
32
- case "$2" in
33
- /*) CONFORMANCE_TESTS_FOLDER="$2" ;;
34
- *) CONFORMANCE_TESTS_FOLDER="$(pwd)/$2" ;;
35
- esac
35
+ # directory on older harnesses; turri passes it as an absolute path - on Windows
36
+ # C:/Users/..., which a test for a leading / would take for a relative one).
37
+ CONFORMANCE_TESTS_FOLDER="$(cd "$2" 2>/dev/null && pwd)" || {
38
+ printf "Error: the conformance tests folder '%s' does not exist.\n" "$2"
39
+ exit 2
40
+ }
36
41
 
37
42
  # Conformance tests live in the conformance tests folder and nowhere else. One in the
38
43
  # build folder is in the wrong place: nothing would run it as part of the suite. Refuse.
@@ -61,54 +66,45 @@ mkdir -p "$PYTHON_BUILD_SUBFOLDER"
61
66
  cp -R "$1"/* "$PYTHON_BUILD_SUBFOLDER"
62
67
 
63
68
  # Move to the subfolder
64
- cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null
65
-
66
- if [ $? -ne 0 ]; then
69
+ if ! cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null; then
67
70
  printf "Error: Python build folder '$PYTHON_BUILD_SUBFOLDER' does not exist.\n"
68
71
  exit $UNRECOVERABLE_ERROR_EXIT_CODE
69
72
  fi
70
73
 
71
- printf "Creating and activating virtual environment...\n"
74
+ printf "Creating the virtual environment...\n"
72
75
 
73
- # Time the virtual environment creation and activation
74
- start_time=$(date +%s.%N)
76
+ # Time the virtual environment's setup: bash's own SECONDS, as `date +%N` is GNU's alone and bc is not everywhere.
77
+ SECONDS=0
75
78
 
76
79
  VENV_DIR=".venv"
77
80
 
78
- if ! $PYTHON_CMD -m venv "$VENV_DIR"; then
81
+ if ! "$PYTHON_CMD" -m venv "$VENV_DIR"; then
79
82
  printf "Error: Failed to create virtual environment in '$VENV_DIR'.\n"
80
83
  exit $UNRECOVERABLE_ERROR_EXIT_CODE
81
84
  fi
82
85
 
83
- # shellcheck disable=SC1091
84
- source "$VENV_DIR/bin/activate"
85
-
86
- if [ $? -ne 0 ]; then
87
- printf "Error: Failed to activate virtual environment at '$VENV_DIR/bin/activate'.\n"
88
- exit $UNRECOVERABLE_ERROR_EXIT_CODE
89
- fi
86
+ # The venv's own tools, called by path rather than activated: in bin/ on macOS and Linux, in Scripts/ on Windows.
87
+ if [ -d "$VENV_DIR/Scripts" ]; then VENV_BIN="$VENV_DIR/Scripts"; else VENV_BIN="$VENV_DIR/bin"; fi
88
+ VENV_PYTHON="$VENV_BIN/python"
89
+ printf "Virtual environment: %s (%s)\n" "$VENV_DIR" "$("$VENV_PYTHON" --version 2>&1)"
90
90
 
91
91
  # Install requirements if requirements.txt exists
92
92
  if [ -f "requirements.txt" ]; then
93
- pip install --upgrade pip
94
- pip install -r requirements.txt
93
+ "$VENV_PYTHON" -m pip install --upgrade pip
94
+ "$VENV_PYTHON" -m pip install -r requirements.txt || exit $?
95
95
  else
96
96
  echo "Warning: requirements.txt not found. Cannot proceed with setting up requirements. The requirements may also already be installed"
97
97
  fi
98
98
 
99
- end_time=$(date +%s.%N)
100
-
101
- # Calculate and display the time taken
102
- duration=$(echo "$end_time - $start_time" | bc)
103
- printf "Requirements setup completed in %.2f seconds\n\n" "$duration"
99
+ printf "Requirements setup completed in %d seconds\n\n" "$SECONDS"
104
100
 
105
101
  # Static checks of the conformance tests - and only them - in the environment they run in, the build installed: ruff's
106
102
  # formatter in check mode, ruff's linter and mypy with a tests profile. The settings are pinned here, in a config the
107
103
  # script writes into the working folder; none is read from the tests folder, whose files the conformance agent writes.
108
104
  STATIC_CHECKS_FAILED=80
109
105
  printf "Static checks of the conformance tests in %s...\n" "$CONFORMANCE_TESTS_FOLDER"
110
- echo "+ pip install ruff mypy"
111
- pip install ruff mypy || exit $?
106
+ echo "+ $VENV_PYTHON -m pip install ruff mypy"
107
+ "$VENV_PYTHON" -m pip install ruff mypy || exit $?
112
108
  cat > .conformance-mypy.ini <<'INI'
113
109
  [mypy]
114
110
  disallow_untyped_defs = True
@@ -117,17 +113,17 @@ ignore_missing_imports = True
117
113
  INI
118
114
  CHECKS=0
119
115
  echo "+ ruff format --check --no-cache --isolated --output-format concise $CONFORMANCE_TESTS_FOLDER"
120
- ruff format --check --no-cache --isolated --output-format concise "$CONFORMANCE_TESTS_FOLDER" || CHECKS=1
116
+ "$VENV_BIN/ruff" format --check --no-cache --isolated --output-format concise "$CONFORMANCE_TESTS_FOLDER" || CHECKS=1
121
117
  echo "+ ruff check --no-cache --isolated --output-format concise --no-fix $CONFORMANCE_TESTS_FOLDER"
122
- ruff check --no-cache --isolated --output-format concise --no-fix "$CONFORMANCE_TESTS_FOLDER" || CHECKS=1
118
+ "$VENV_BIN/ruff" check --no-cache --isolated --output-format concise --no-fix "$CONFORMANCE_TESTS_FOLDER" || CHECKS=1
123
119
  echo "+ mypy --config-file .conformance-mypy.ini --cache-dir ./.mypy_cache --no-color-output --show-column-numbers $CONFORMANCE_TESTS_FOLDER"
124
- mypy --config-file .conformance-mypy.ini --cache-dir ./.mypy_cache --no-color-output --show-column-numbers "$CONFORMANCE_TESTS_FOLDER" || CHECKS=1
120
+ "$VENV_BIN/mypy" --config-file .conformance-mypy.ini --cache-dir ./.mypy_cache --no-color-output --show-column-numbers "$CONFORMANCE_TESTS_FOLDER" || CHECKS=1
125
121
  [ "$CHECKS" -eq 0 ] && printf "Static checks: passed\n\n" || printf "Static checks: FAILED - the findings are above\n\n"
126
122
 
127
123
  # Execute all Python conformance tests in the build folder - whatever the checks said, so one run reports both
128
124
  printf "Running Python conformance tests...\n\n"
129
125
 
130
- output=$($PYTHON_CMD -m unittest discover -b -s "$CONFORMANCE_TESTS_FOLDER" 2>&1)
126
+ output=$("$VENV_PYTHON" -m unittest discover -b -s "$CONFORMANCE_TESTS_FOLDER" 2>&1)
131
127
  exit_code=$?
132
128
 
133
129
  # Echo the original output
@@ -24,9 +24,9 @@ The reference implementation is [assets/run_unittests_java.sh](assets/run_unitte
24
24
 
25
25
  ## Always Bash
26
26
 
27
- turri requires this script and runs it itself, as `bash run_unittests_<lang>.sh <build_folder>` on the person's machine - macOS, Linux or WSL: its exit code decides whether a functional spec's unit tests pass. So the script is always **Bash (`.sh`)**, and stays portable across them - POSIX tools and flags, nothing only one of them has.
27
+ turri requires this script and runs it itself, as `bash run_unittests_<lang>.sh <build_folder>` on the person's machine - macOS, Linux or Windows, where bash is Git Bash: its exit code decides whether a functional spec's unit tests pass. So the script is always **Bash (`.sh`)**, and stays portable across them - see [Bash specifics](#bash-specifics).
28
28
 
29
- A **PowerShell (`.ps1`)** copy is written only when the user asks for one, to run the tests by hand on native Windows. turri never runs it, so a project with only a `.ps1` has no unit testing script.
29
+ A **PowerShell (`.ps1`)** copy is written only when the user asks for one, to run the tests by hand in PowerShell. turri never runs it, so a project with only a `.ps1` has no unit testing script.
30
30
 
31
31
  The same eight-step pattern applies to both. Only the syntax changes.
32
32
 
@@ -35,7 +35,7 @@ The same eight-step pattern applies to both. Only the syntax changes.
35
35
  Every testing script must implement these steps **in this order**:
36
36
 
37
37
  1. **Toolchain check.** Verify that the required language runtime / build tool (and the required version, if any) is installed. If not, print an error and exit with code `69`.
38
- 2. **Argument validation.** Require exactly one positional argument: the source build folder. If missing, print usage and exit with code `1`. turri passes this argument as an **absolute path** (older harnesses passed a relative one) — the script must work with both, which is why the working-folder name in step 3 is built from the argument's *basename*, never from the raw argument.
38
+ 2. **Argument validation.** Require exactly one positional argument: the source build folder. If missing, print usage and exit with code `1`. turri passes this argument as an **absolute path** (older harnesses passed a relative one; on Windows it is written with forward slashes, `C:/Users/...`) — the script must work with both, which is why the working-folder name in step 3 is built from the argument's *basename*, never from the raw argument.
39
39
  3. **Working directory setup.** Define a working folder in the **system temp directory**: `/tmp/<lang>_$(basename "$1")` in Bash, `Join-Path ([System.IO.Path]::GetTempPath()) "<lang>_$(Split-Path $BuildFolder -Leaf)"` in PowerShell (written as `<temp>/<lang>_<basename>` below). If it exists, wipe its contents; otherwise create it. Register cleanup so the folder is removed when the script exits — `trap 'rm -rf "$WORKING_FOLDER"' EXIT` in Bash, a `Remove-Item -Recurse -Force` in the `finally` block in PowerShell. This folder — and **only** this folder — is where every subsequent write must land.
40
40
  4. **Copy the build.** Recursively copy everything from the source folder into the working folder. After this step the source folder (`$1`) is treated as **read-only** for the rest of the script.
41
41
  5. **Enter the working directory.** `cd` / `Set-Location` into `<temp>/<lang>_<basename>`. If that fails, exit with code `2`. All remaining steps run from inside the working folder; they must never write back to the source build folder.
@@ -84,7 +84,7 @@ The dependency environment must live **inside** `$WORKING_FOLDER` so the test ru
84
84
 
85
85
  | Language | Isolation mechanism | Install command (run inside `$WORKING_FOLDER`) | Test command |
86
86
  |---|---|---|---|
87
- | Python | `venv` at `./.venv` | `python3 -m venv .venv && ./.venv/bin/pip install -r requirements.txt` (or `pyproject.toml` / `uv sync` / `poetry install`) | `./.venv/bin/pytest` (or `./.venv/bin/python -m pytest`) |
87
+ | Python | `venv` at `./.venv` | `"$PYTHON" -m venv .venv && "$VENV_BIN/python" -m pip install -r requirements.txt` (or `pyproject.toml` / `uv sync` / `poetry install`) - `$VENV_BIN` is `.venv/bin`, or `.venv/Scripts` on Windows | `"$VENV_BIN/pytest"` (or `"$VENV_BIN/python" -m pytest`) |
88
88
  | Node.js | local `./node_modules` (default) | `npm ci` (preferred) or `npm install` | `npm test` |
89
89
  | Java | project-scoped Maven repo at `./.m2` | `mvn -Dmaven.repo.local=./.m2 dependency:resolve` (optional pre-warm) | `mvn -Dmaven.repo.local=./.m2 test` |
90
90
  | Go | module cache at `./.gocache` | `GOMODCACHE="$PWD/.gocache" go mod download` (optional pre-warm) | `GOMODCACHE="$PWD/.gocache" go test ./...` |
@@ -96,7 +96,7 @@ Notes:
96
96
  - **Always pass the isolation flag/env var to both the install command and the test command** — they must agree on where deps live, otherwise the test command will silently fall back to the global cache **or** (worse) the source build folder.
97
97
  - **Python is the only ecosystem where the venv is mandatory** to satisfy "into a virtual environment" literally. The others use language-native equivalents that achieve the same isolation.
98
98
  - **Pre-warming is optional for Java/Go/Rust** — their test commands will fetch deps on demand. Doing it as a separate step makes failures easier to diagnose and gives a clean "install failed vs test failed" signal.
99
- - **Don't activate the venv** in Bash via `source .venv/bin/activate` — call `./.venv/bin/<tool>` directly. It's more portable and avoids subshell weirdness. In PowerShell, use `& .\.venv\Scripts\<tool>.exe` similarly.
99
+ - **Don't activate the venv** in Bash via `source .venv/bin/activate` — call `"$VENV_BIN/<tool>"` directly, `$VENV_BIN` being `.venv/bin`, or `.venv/Scripts` on Windows. It's more portable and avoids subshell weirdness. In PowerShell, use `& .\.venv\Scripts\<tool>.exe` similarly.
100
100
  - **Propagate the install exit code immediately.** In Bash: `<install cmd> || exit $?`. In PowerShell: check `$LASTEXITCODE` and `exit $LASTEXITCODE` if non-zero.
101
101
 
102
102
  ### Static checks
@@ -122,10 +122,18 @@ Notes:
122
122
 
123
123
  ### Bash specifics
124
124
 
125
- - **Shebang:** `#!/bin/bash`.
125
+ - **Shebang:** `#!/usr/bin/env bash` - turri runs it with `bash` itself, and a person running it by hand gets the bash on their PATH, which is not at `/bin/bash` everywhere.
126
126
  - **File naming:** `run_unittests_<lang>.sh`, placed in `assets/` (skill reference) or `test_scripts/` (target project).
127
127
  - **Argument:** `$1`.
128
128
  - **Make it executable:** `chmod +x test_scripts/run_unittests_<lang>.sh`.
129
+ - **Portable - macOS, Linux and Windows alike.** turri runs the script with the `bash` on the person's PATH: on macOS often the system's own bash 3.2, on Windows Git Bash. Write it for all three:
130
+ - bash 3.2's features only - no `mapfile` / `readarray`, `declare -A`, `${var,,}`, `|&`;
131
+ - tools and flags that GNU, BSD and Git Bash all have (`cp -R`, `mktemp -d`, `find`, `grep -E` with `[[:space:]]` rather than `\s`, `sed` without `-i`), and none that only some machines have: not `tree`, `bc`, `jq`, `realpath`, `timeout`, `date +%N` (time with bash's own `SECONDS`), not macOS's `/usr/libexec/java_home` (take `JAVA_HOME`, else the `java` on the PATH);
132
+ - a folder argument resolved with `$(cd "$1" && pwd)`, never told absolute by a leading `/`: on Windows turri passes `C:/Users/...`;
133
+ - every path quoted: a Windows home has spaces in it (`C:/Users/Ana Lee`);
134
+ - a path a native tool reads from a file the script writes - a config, a settings file - relative to the working folder, as Git Bash's `/tmp/...` means nothing to a Windows program reading a file;
135
+ - a Python venv keeps its tools in `.venv/bin`, on Windows in `.venv/Scripts`: pick the one that is there (`if [ -d .venv/Scripts ]; then VENV_BIN=.venv/Scripts; else VENV_BIN=.venv/bin; fi`) and call them by path. And on Windows `python3` may be the Microsoft Store's stand-in, which runs nothing: take the first of `python3` and `python` that runs `-c "import sys"`;
136
+ - LF line endings - bash cannot run a script with CRLF ones, which a Windows checkout under git's `core.autocrlf` makes of it. When the project is a git repository whose `.gitattributes` lacks `*.sh text eol=lf`, say so in your result.
129
137
 
130
138
  ### PowerShell specifics
131
139
 
@@ -1,13 +1,24 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
- # Check that Java 21 is installed
4
- if ! /usr/libexec/java_home -v 21 >/dev/null 2>&1; then
5
- echo "Error: Java 21 is not installed."
3
+ # Java 21 or newer, and Maven: JAVA_HOME's java when it is set, else the one on the PATH - the same on macOS, Linux
4
+ # and Windows (Git Bash). Not macOS's /usr/libexec/java_home, which no other OS has.
5
+ JAVA="java"
6
+ [ -n "${JAVA_HOME:-}" ] && JAVA="$JAVA_HOME/bin/java"
7
+ if ! "$JAVA" -version >/dev/null 2>&1; then
8
+ echo "Error: Java is not installed (no $JAVA)."
6
9
  exit 69
7
10
  fi
8
-
9
- export JAVA_HOME=$(/usr/libexec/java_home -v 21)
10
- java --version
11
+ JAVA_VERSION="$("$JAVA" -version 2>&1 | sed -n 's/.*version "\([0-9]*\).*/\1/p' | head -n 1)"
12
+ if [ -z "$JAVA_VERSION" ] || [ "$JAVA_VERSION" -lt 21 ]; then
13
+ echo "Error: Java 21 or newer is needed; $JAVA is Java ${JAVA_VERSION:-of a version it does not say}."
14
+ exit 69
15
+ fi
16
+ if ! command -v mvn >/dev/null 2>&1; then
17
+ echo "Error: Maven (mvn) is not installed."
18
+ exit 69
19
+ fi
20
+ "$JAVA" -version
21
+ mvn --version
11
22
 
12
23
  # Check if subfolder name is provided
13
24
  if [ -z "$1" ]; then
@@ -36,12 +47,11 @@ fi
36
47
  cp -R "$1"/* "$WORKING_FOLDER"
37
48
  printf "Copied from $1 to $WORKING_FOLDER...\n"
38
49
  # Move to the subfolder
39
- cd "$WORKING_FOLDER" 2>/dev/null
40
- printf "Moved to $WORKING_FOLDER...\n"
41
- if [ $? -ne 0 ]; then
42
- echo "Error: Subfolder '$1' does not exist."
50
+ if ! cd "$WORKING_FOLDER" 2>/dev/null; then
51
+ echo "Error: cannot enter the working folder '$WORKING_FOLDER'."
43
52
  exit 2
44
53
  fi
54
+ printf "Moved to $WORKING_FOLDER...\n"
45
55
 
46
56
  # Static checks: the code compiled with every javac lint warning an error - the flags pinned here, not in the pom.
47
57
  # A formatter runs only when the implementation reqs name one (mvn spotless:check, say). Every check runs, and the
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  # The unit tests of a Python build, with its static checks: ruff's formatter in check mode, ruff's linter and mypy,
3
3
  # each from the project's own `dev` dependency group, then pytest - as stdlib/lang/python asks for them.
4
4
  #
@@ -52,31 +52,35 @@ if [ ! -f pyproject.toml ]; then
52
52
  echo "Error: there is no pyproject.toml - the project's dependencies, pytest, ruff and mypy among them, go in it."
53
53
  exit 1
54
54
  fi
55
- export UV_PROJECT_ENVIRONMENT="$WORKING_FOLDER/.venv" UV_PYTHON="$PYTHON" UV_PYTHON_DOWNLOADS=never
56
- export UV_CACHE_DIR="${UV_CACHE_DIR:-$WORKING_FOLDER/.uv-cache}" PYTHONDONTWRITEBYTECODE=1
55
+ # Relative to the working folder, where the script now is: a path a native Windows uv reads as it is, from Git Bash too.
56
+ export UV_PROJECT_ENVIRONMENT=".venv" UV_PYTHON="$PYTHON" UV_PYTHON_DOWNLOADS=never
57
+ export UV_CACHE_DIR="${UV_CACHE_DIR:-.uv-cache}" PYTHONDONTWRITEBYTECODE=1
57
58
  unset PYTHONPATH PYTHONHOME
58
- echo "+ uv sync (the project and its dev dependency group into $UV_PROJECT_ENVIRONMENT)"
59
+ echo "+ uv sync (the project and its dev dependency group into $WORKING_FOLDER/.venv)"
59
60
  uv sync || exit $?
61
+ # The venv's own tools: in bin/ on macOS and Linux, in Scripts/ on Windows.
62
+ if [ -d .venv/Scripts ]; then VENV_BIN=.venv/Scripts; else VENV_BIN=.venv/bin; fi
60
63
 
61
64
  echo "===== [7/8] Static checks ====="
62
65
  CHECKS=0
63
66
  for tool in ruff mypy; do
64
- if [ ! -x ".venv/bin/$tool" ]; then
67
+ if [ ! -x "$VENV_BIN/$tool" ]; then
65
68
  echo "pyproject.toml:1:1: $tool is not in the dev dependency group - add it with \`uv add --dev $tool\`"
66
69
  CHECKS=1
67
70
  fi
68
71
  done
69
- if [ -x .venv/bin/ruff ]; then
70
- echo "+ ruff format --check --output-format concise ."
71
- .venv/bin/ruff format --check --output-format concise . || CHECKS=1
72
- echo "+ ruff check --output-format concise --no-fix ."
73
- .venv/bin/ruff check --output-format concise --no-fix . || CHECKS=1
72
+ if [ -x "$VENV_BIN/ruff" ]; then
73
+ # Not uv's cache, kept in the working folder when the person has none of their own: its files are not the build's.
74
+ echo "+ ruff format --check --output-format concise --extend-exclude .uv-cache ."
75
+ "$VENV_BIN/ruff" format --check --output-format concise --extend-exclude .uv-cache . || CHECKS=1
76
+ echo "+ ruff check --output-format concise --no-fix --extend-exclude .uv-cache ."
77
+ "$VENV_BIN/ruff" check --output-format concise --no-fix --extend-exclude .uv-cache . || CHECKS=1
74
78
  fi
75
- if [ -x .venv/bin/mypy ]; then
79
+ if [ -x "$VENV_BIN/mypy" ]; then
76
80
  # `files` in [tool.mypy] says what to check; without it, the whole build.
77
- if grep -Eq '^\s*files\s*=' pyproject.toml; then TARGETS=(); else TARGETS=(.); fi
81
+ if grep -Eq '^[[:space:]]*files[[:space:]]*=' pyproject.toml; then TARGETS=(); else TARGETS=(.); fi
78
82
  echo "+ mypy --no-color-output --show-column-numbers ${TARGETS[*]:-}"
79
- .venv/bin/mypy --no-color-output --show-column-numbers ${TARGETS[@]+"${TARGETS[@]}"} || CHECKS=1
83
+ "$VENV_BIN/mypy" --no-color-output --show-column-numbers ${TARGETS[@]+"${TARGETS[@]}"} || CHECKS=1
80
84
  fi
81
85
  [ "$CHECKS" -eq 0 ] && echo "Static checks: passed" || echo "Static checks: FAILED - the findings are above"
82
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turri-dev/cli",
3
- "version": "0.3.1-next.f3b1920",
3
+ "version": "0.4.1-next.2e3d7a6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {