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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Verify package behavior
run: node scripts/verify.mjs
- name: Verify process observation
run: node --test scripts/observe-process.test.mjs scripts/verify-native-web.test.mjs
run: node --test scripts/command.test.mjs scripts/observe-process.test.mjs scripts/verify-native-web.test.mjs

- name: Verify native applications
if: github.event_name == 'workflow_dispatch'
Expand Down
14 changes: 14 additions & 0 deletions scripts/command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';

export function runCommand(args, cwd, cli) {
const script = process.platform === 'win32' && /\.(bat|cmd)$/i.test(cli);
const result = spawnSync(script ? process.env.ComSpec : cli,
script ? ['/d', '/c', 'call', cli, ...args] : args,
{ cwd, encoding: 'utf8', timeout: 1200000, windowsHide: true });
if (result.error) throw result.error;
assert.equal(result.status, 0, result.stderr + result.stdout);
process.stdout.write(result.stdout);
process.stderr.write(result.stderr);
return { stdout: result.stdout, stderr: result.stderr };
}
15 changes: 15 additions & 0 deletions scripts/command.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { runCommand } from './command.mjs';

test('retains build diagnostics on stderr separately from program output', () => {
const result = runCommand(['-e', 'process.stdout.write("program output\\n"); process.stderr.write("Build report: report-directory\\n");'],
process.cwd(), process.execPath);
assert.equal(result.stdout, 'program output\n');
assert.equal(result.stderr, 'Build report: report-directory\n');
});

test('command failures include both real process streams', () => {
assert.throws(() => runCommand(['-e', 'process.stdout.write("out details"); process.stderr.write("err details"); process.exitCode = 3;'],
process.cwd(), process.execPath), /err detailsout details/);
});
2 changes: 1 addition & 1 deletion scripts/verify-native-web.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function verifyNativeWeb(repository, build, measure) {
`${configuration}\nmicronaut: Micronaut(server: Server(port: 0)),`) + '\n' + verification);
const buildOutput = build(['build', source, '--diagnostics'], directory);
const executable = process.platform === 'win32' ? `${source}.exe` : resolve(directory, 'web');
const reports = [...buildOutput.matchAll(/Build report: ([^\r\n]+)/g)];
const reports = [...buildOutput.stderr.matchAll(/Build report: ([^\r\n]+)/g)];
if (reports.length !== 1) throw new Error('Expected one native build report');
const evidenceRoot = resolve(repository, 'build/reports/native');
mkdirSync(evidenceRoot, { recursive: true });
Expand Down
12 changes: 2 additions & 10 deletions scripts/verify.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { resolve } from 'node:path';
import { runCommand } from './command.mjs';
import { verifyNativeWeb } from './verify-native-web.mjs';

const root = resolve(import.meta.dirname, '..');
Expand All @@ -16,12 +15,5 @@ if (process.argv.includes('--native')) {
}

function run(args, cwd = root) {
const script = process.platform === 'win32' && /\.(bat|cmd)$/i.test(cli);
const result = spawnSync(script ? process.env.ComSpec : cli,
script ? ['/d', '/c', 'call', cli, ...args] : args,
{ cwd, encoding: 'utf8', timeout: 1200000, windowsHide: true });
if (result.error) throw result.error;
assert.equal(result.status, 0, result.stderr + result.stdout);
console.log(result.stdout);
return result.stdout;
return runCommand(args, cwd, cli);
}