@juangcarmona/lighthouse-sdlc 0.23.0 → 0.23.1

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.
@@ -73,4 +73,18 @@ The [implementation skill](skills/implement/SKILL.md#workspace-command-slot) use
73
73
 
74
74
  The adapter supervises the image's existing entrypoint and each independent check with the same packaged Node helper. On Linux cgroup v2, it records task peak/limit, task-limit rejections, peak memory and OOM kills while the container still exists. `runtime.json.execution` and each `checks.json` entry retain the sanitized diagnostic summary, exit code and signal. Unsupported counters remain `null`. A confirmed resource rejection, abort, timeout or cancellation fails the attempt; diagnostics do not grant publication or retry authority.
75
75
 
76
+ ### Private scratch and npm downloads
77
+
78
+ Both the agent and each independent check have a private 2 GiB `/tmp` mount. This is a byte limit, not host free space; tmpfs usage also competes with the workload's 4 GiB memory limit. The agent retains scratch across commands, while independent checks receive fresh scratch for each command. Passing independent checks cannot turn a failed local attempt into success.
79
+
80
+ The runtime enables command-owned npm caches through `LIGHTHOUSE_COMMAND_NPM_CACHE=1`. Each managed invocation gives its command group a fresh private directory under `/tmp`, through both npm cache environment spellings. The helper removes only that directory after stopping the group's descendants and before releasing its slot. Success, failure, spawn failure and handled cancellation all dispose downloads; installed workspace dependencies, NuGet packages, .NET state, evidence and inherited caches are not cleanup targets. Nested managed commands own separate directories. Abrupt process death relies on final container removal.
81
+
82
+ Run cold `npm ci` as one managed attempt, wait for its terminal receipt, then run the unchanged .NET restore/verification as the next attempt. Downloads are reusable within a command group, not across groups. Combining installation and verification in a single shell command retains that group's cache until both finish. Explicit npm `--cache` or other cache overrides remain caller-owned and are not reclaimed by this lifecycle. Do not redirect them to host or shared caches.
83
+
84
+ Managed receipts include available scratch bytes before execution and around cleanup when measurable, and the npm cleanup outcome. Allocation or cleanup failure cannot report success. Original failing command output and status remain visible, with capacity diagnostics; `NU1301` alone is not proof of ENOSPC. This lifecycle removes cross-command npm accumulation, not peak demand within a command: NuGet, .NET, browser data and other temporary files must still fit the private byte and memory limits. No arbitrary-workload capacity guarantee is implied.
85
+
86
+ Qualify a .NET consumer on a supported host using a cold install and unchanged verification under these limits. Retain the local receipts and separate independent results for the exact same candidate. Small synthetic demand regressions establish cleanup boundaries, not native capacity acceptance or installed rollout.
87
+
88
+ From the source repository root, run `LIGHTHOUSE_TEST_SCRATCH_IMAGE=sha256:<image-id> LIGHTHOUSE_SCRATCH_EVIDENCE=<absolute-json-path> node --test src/tests/command-scratch.integration.test.mjs` for the real npm-to-.NET regression. The supplied image must satisfy the example's current SDK and Aspire CLI bundle prerequisites. The test keeps failure logs and completed receipts, uses cold private scratch for installation and .NET verification in sequence, and repeats .NET verification in a separate container. This standalone test does not establish a native workflow result or installed rollout.
89
+
76
90
  Adapter and mounted-skill updates require a new workflow source pin, without an engine-image rebuild. Rebuild only when changing tools, the engine binary or baked image policy. Follow the [workflow update procedure](README.md#install-or-update-workflows), validate on one consumer, then roll out to the remaining repositories between runs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juangcarmona/lighthouse-sdlc",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "type": "module",
5
5
  "description": "Provider-neutral SDLC skills, commands and route contracts for Lighthouse adopters",
6
6
  "repository": {
@@ -0,0 +1,35 @@
1
+ import { mkdtempSync, rmSync, statfsSync } from 'node:fs';
2
+
3
+ const filesystem = { mkdtempSync, rmSync, statfsSync };
4
+ export const scratchErrorCode = error => ['ENOSPC', 'EDQUOT', 'EACCES', 'EPERM', 'EROFS', 'ENOTDIR'].includes(error?.code) ? error.code : null;
5
+
6
+ export function scratchCapacity(io = filesystem) {
7
+ try {
8
+ const { blocks, bavail, bsize } = io.statfsSync('/tmp');
9
+ return { capacityBytes: blocks * bsize, availableBytes: bavail * bsize };
10
+ } catch { return null; }
11
+ }
12
+
13
+ // The runtime opts in only inside its private /tmp. Never clean a configured cache path.
14
+ export function commandScratch(environment, io = filesystem) {
15
+ if (environment.LIGHTHOUSE_COMMAND_NPM_CACHE !== '1') return null;
16
+ const path = io.mkdtempSync('/tmp/lighthouse-npm-');
17
+ const receipt = { npmCache: 'active', beforeCommand: scratchCapacity(io) };
18
+ return {
19
+ environment: { ...environment, NPM_CONFIG_CACHE: path, npm_config_cache: path },
20
+ receipt,
21
+ release() {
22
+ if (receipt.npmCache !== 'active') return receipt.npmCache === 'released';
23
+ receipt.beforeCleanup = scratchCapacity(io);
24
+ try { io.rmSync(path, { recursive: true, force: true }); receipt.npmCache = 'released'; }
25
+ catch (error) { receipt.npmCache = 'cleanup-failed'; receipt.errorCode = scratchErrorCode(error); }
26
+ receipt.afterCleanup = scratchCapacity(io);
27
+ return receipt.npmCache === 'released';
28
+ },
29
+ };
30
+ }
31
+
32
+ export function scratchDiagnostic(receipt) {
33
+ const capacity = receipt.afterCleanup ?? receipt.beforeCommand;
34
+ return `Private scratch: ${capacity ? `${capacity.availableBytes} of ${capacity.capacityBytes} bytes available` : 'capacity unavailable'}; npm cache ${receipt.npmCache}${receipt.errorCode ? ` (${receipt.errorCode})` : ''}. ENOSPC indicates exhausted scratch; NU1301 alone does not establish capacity exhaustion.`;
35
+ }
@@ -1,5 +1,6 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { readFile, lstat } from 'node:fs/promises';
3
+ import { scratchErrorCode } from './command-scratch.mjs';
3
4
 
4
5
  export function executionLimits(config, implementing = true) {
5
6
  const resources = config.resources === undefined ? {} : config.resources;
@@ -35,8 +36,19 @@ export async function executionReceipt(path, exit, reason = null) {
35
36
  }
36
37
  const signal = /^SIG[A-Z0-9]+$/.test(observed.signal ?? '') ? observed.signal : exit.signal ?? null;
37
38
  const exitCode = Number.isInteger(exit.code) ? exit.code : null;
38
- const status = reason ?? (observed.state === 'cancelled' ? 'cancelled' : resources.oomKills > 0 ? 'out-of-memory' : resources.pidsDenied > 0 ? 'process-limit' : exitCode === 0 ? 'passed' : signal === 'SIGABRT' || exitCode === 134 ? 'aborted' : 'failed');
39
- return { status, exitCode, signal, resources, ...(Number.isSafeInteger(observed.resourceSamplesDropped) && observed.resourceSamplesDropped > 0 ? { resourceSamplesDropped: observed.resourceSamplesDropped } : {}) };
39
+ const scratchFailed = ['active', 'allocation-failed', 'cleanup-failed'].includes(observed.scratch?.npmCache);
40
+ const status = reason ?? (observed.state === 'cancelled' ? 'cancelled' : resources.oomKills > 0 ? 'out-of-memory' : resources.pidsDenied > 0 ? 'process-limit' : scratchFailed ? 'failed' : exitCode === 0 ? 'passed' : signal === 'SIGABRT' || exitCode === 134 ? 'aborted' : 'failed');
41
+ let scratch;
42
+ if (['active', 'released', 'allocation-failed', 'cleanup-failed'].includes(observed.scratch?.npmCache)) {
43
+ scratch = { npmCache: observed.scratch.npmCache };
44
+ const errorCode = scratchErrorCode({ code: observed.scratch.errorCode });
45
+ if (errorCode) scratch.errorCode = errorCode;
46
+ for (const key of ['beforeCommand', 'beforeCleanup', 'afterCleanup']) {
47
+ const value = observed.scratch[key];
48
+ scratch[key] = value && Number.isSafeInteger(value.capacityBytes) && Number.isSafeInteger(value.availableBytes) && value.capacityBytes >= 0 && value.availableBytes >= 0 && value.availableBytes <= value.capacityBytes ? { capacityBytes: value.capacityBytes, availableBytes: value.availableBytes } : null;
49
+ }
50
+ }
51
+ return { status, exitCode, signal, resources, ...(scratch ? { scratch } : {}), ...(Number.isSafeInteger(observed.resourceSamplesDropped) && observed.resourceSamplesDropped > 0 ? { resourceSamplesDropped: observed.resourceSamplesDropped } : {}) };
40
52
  }
41
53
 
42
54
  export function executionFailure(receipt) {
@@ -84,7 +84,7 @@ export async function copyEvidence(source, destination) {
84
84
  }
85
85
 
86
86
  // Scratch belongs to the disposable container, never the retained evidence tree.
87
- export const scratchArgs = ['--env', 'TMPDIR=/tmp', '--env', 'NPM_CONFIG_CACHE=/tmp/npm-cache', '--env', 'XDG_CACHE_HOME=/tmp/cache', '--env', 'NODE_DISABLE_COMPILE_CACHE=1'];
87
+ export const scratchArgs = ['--env', 'TMPDIR=/tmp', '--env', 'NPM_CONFIG_CACHE=/tmp/npm-cache', '--env', 'LIGHTHOUSE_COMMAND_NPM_CACHE=1', '--env', 'XDG_CACHE_HOME=/tmp/cache', '--env', 'NODE_DISABLE_COMPILE_CACHE=1'];
88
88
  // A regular-file stdout prevents providers using process.exit() from truncating pending pipe writes.
89
89
  const checkOutputCommand = 'node /harness/src/managed-command.mjs run /diagnostics "$@" > /tmp/lighthouse-check.log 2>&1; check_exit=$?; cat /tmp/lighthouse-check.log || exit 125; exit "$check_exit"';
90
90
  export async function runImplementationChecks({ config, request, changes, workspace, output, name, redact, cancelled, selected = null, repository = request.repository, telemetry }) {
@@ -4,6 +4,7 @@ import { join, resolve } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { spawn } from 'node:child_process';
6
6
  import { constants } from 'node:os';
7
+ import { commandScratch, scratchCapacity, scratchDiagnostic, scratchErrorCode } from './command-scratch.mjs';
7
8
 
8
9
  const number = path => { try { const value = Number(readFileSync(path, 'utf8').trim()); return Number.isSafeInteger(value) && value >= 0 ? value : null; } catch { return null; } };
9
10
  const counter = (path, key) => { try { const line = readFileSync(path, 'utf8').split('\n').find(line => line.startsWith(key + ' ')); return line ? Number(line.split(' ')[1]) : null; } catch { return null; } };
@@ -17,7 +18,7 @@ export function workloadResources() {
17
18
  return { cpuUsageUsec: counter('/sys/fs/cgroup/cpu.stat', 'usage_usec'), memoryBytes: number('/sys/fs/cgroup/memory.current'), memoryPeakBytes: number('/sys/fs/cgroup/memory.peak'), pids: number('/sys/fs/cgroup/pids.current'), readBytes: io?.rbytes ?? null, writeBytes: io?.wbytes ?? null, networkRxBytes: network?.rx ?? null, networkTxBytes: network?.tx ?? null };
18
19
  }
19
20
 
20
- export async function managedCommand(directory, id, command) {
21
+ export async function managedCommand(directory, id, command, { createScratch = commandScratch } = {}) {
21
22
  if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(id) || !command.length) throw Error('Use a unique command ID and an executable');
22
23
  mkdirSync(directory, { recursive: true });
23
24
  const lock = join(directory, '.active'), receipt = join(directory, id + '.json');
@@ -25,7 +26,7 @@ export async function managedCommand(directory, id, command) {
25
26
  if (error.code !== 'EEXIST') throw error;
26
27
  throw Error('Another command owns this workspace command slot; wait for its receipt or stop it before retrying');
27
28
  }
28
- let child, interval, stopping = false;
29
+ let child, interval, scratch, stopping = false;
29
30
  const signalGroup = signal => { if (child?.pid) { try { process.kill(-child.pid, signal); } catch (error) { if (error.code !== 'ESRCH') throw error; } } };
30
31
  const stop = () => { stopping = true; signalGroup('SIGTERM'); };
31
32
  process.once('SIGTERM', stop); process.once('SIGINT', stop);
@@ -50,7 +51,16 @@ export async function managedCommand(directory, id, command) {
50
51
  if (existsSync(receipt)) throw Error('Command ID already has a receipt; use a new ID for the next attempt');
51
52
  atomic(join(lock, 'owner.json'), { pid: process.pid, startTicks: state.startTicks });
52
53
  sample();
53
- child = spawn(command[0], command.slice(1), { stdio: 'inherit', detached: true });
54
+ try { scratch = createScratch(process.env); }
55
+ catch (error) {
56
+ state.scratch = { npmCache: 'allocation-failed', errorCode: scratchErrorCode(error), beforeCommand: scratchCapacity() };
57
+ state.state = 'completed'; state.exitCode = 125;
58
+ console.error(scratchDiagnostic(state.scratch));
59
+ sample();
60
+ return state.exitCode;
61
+ }
62
+ if (scratch) state.scratch = scratch.receipt;
63
+ child = spawn(command[0], command.slice(1), { stdio: 'inherit', detached: true, env: scratch?.environment ?? process.env });
54
64
  let killTimer;
55
65
  const forceStop = () => { stop(); killTimer = setTimeout(() => signalGroup('SIGKILL'), 1000); };
56
66
  process.removeListener('SIGTERM', stop); process.removeListener('SIGINT', stop);
@@ -66,15 +76,20 @@ export async function managedCommand(directory, id, command) {
66
76
  await new Promise(resolve => setTimeout(resolve, 100));
67
77
  signalGroup('SIGKILL');
68
78
  clearTimeout(killTimer);
79
+ const released = scratch?.release() ?? true;
69
80
  state.state = stopping ? 'cancelled' : 'completed';
70
81
  state.signal = exit.signal;
71
82
  state.exitCode = exit.code ?? 128 + (constants.signals[exit.signal] ?? 0);
83
+ if (stopping && state.exitCode === 0) state.exitCode = 143;
84
+ if (!released && state.exitCode === 0) state.exitCode = 125;
85
+ if (state.exitCode !== 0 && state.scratch) console.error(scratchDiagnostic(state.scratch));
72
86
  sample();
73
87
  return state.exitCode;
74
88
  } finally { process.removeListener('SIGTERM', forceStop); process.removeListener('SIGINT', forceStop); }
75
89
  } finally {
76
90
  clearInterval(interval);
77
91
  signalGroup('SIGKILL');
92
+ scratch?.release();
78
93
  process.removeListener('SIGTERM', stop); process.removeListener('SIGINT', stop);
79
94
  rmSync(lock, { recursive: true, force: true });
80
95
  }