Skip to content

Commit 0fb0c44

Browse files
committed
fix: exercise valid Rust release smoke
1 parent ee21e68 commit 0fb0c44

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

scripts/rust-distribution.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -849,13 +849,7 @@ function run() {
849849
}
850850
if (command === 'smoke') {
851851
const binaryPath = path.resolve(argument('binary'));
852-
const result = childProcess.spawnSync(binaryPath, [], { stdio: 'inherit' });
853-
if (result.error) throw result.error;
854-
if (result.signal || result.status !== 0) {
855-
throw new Error(
856-
`RUST_BINARY_SMOKE_FAILED: status=${result.status} signal=${result.signal || 'none'}`
857-
);
858-
}
852+
smokeExecutable(binaryPath, 'RUST_BINARY_SMOKE_FAILED');
859853
process.stdout.write(`Rust release executable exited 0: ${binaryPath}\n`);
860854
return;
861855
}
@@ -871,13 +865,7 @@ function run() {
871865
declaration.executable
872866
);
873867
fs.writeFileSync(binaryPath, executable, { mode: 0o755 });
874-
const result = childProcess.spawnSync(binaryPath, [], { stdio: 'inherit' });
875-
if (result.error) throw result.error;
876-
if (result.signal || result.status !== 0) {
877-
throw new Error(
878-
`RUST_ARCHIVE_SMOKE_FAILED: status=${result.status} signal=${result.signal || 'none'}`
879-
);
880-
}
868+
smokeExecutable(binaryPath, 'RUST_ARCHIVE_SMOKE_FAILED');
881869
} finally {
882870
fs.rmSync(directory, { recursive: true, force: true });
883871
}
@@ -903,6 +891,26 @@ function run() {
903891
);
904892
}
905893

894+
const SMOKE_GREETING = Buffer.from('zeroshot release smoke\n');
895+
896+
function smokeExecutable(binaryPath, failureCode) {
897+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'zeroshot-rust-executable-smoke-'));
898+
try {
899+
fs.writeFileSync(path.join(directory, 'greeting.txt'), SMOKE_GREETING);
900+
const result = childProcess.spawnSync(binaryPath, ['--native-validate-greeting'], {
901+
cwd: directory,
902+
input: SMOKE_GREETING,
903+
stdio: ['pipe', 'inherit', 'inherit'],
904+
});
905+
if (result.error) throw result.error;
906+
if (result.signal || result.status !== 0) {
907+
throw new Error(`${failureCode}: status=${result.status} signal=${result.signal || 'none'}`);
908+
}
909+
} finally {
910+
fs.rmSync(directory, { recursive: true, force: true });
911+
}
912+
}
913+
906914
if (require.main === module) {
907915
try {
908916
run();
@@ -926,6 +934,7 @@ module.exports = {
926934
packageTarget,
927935
parseChecksumManifest,
928936
sha256,
937+
smokeExecutable,
929938
targetForHost,
930939
stageVersion,
931940
targets,

tests/unit/rust-distribution.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ describe('Rust product distribution', function () {
8989
});
9090
});
9191

92+
describe('Rust release executable smoke', function () {
93+
it('uses the valid greeting-validator protocol', function () {
94+
if (process.platform === 'win32') this.skip();
95+
const directory = temporaryDirectory();
96+
const binaryPath = path.join(directory, 'fixture-binary');
97+
fs.writeFileSync(
98+
binaryPath,
99+
`#!/bin/sh
100+
[ "$1" = "--native-validate-greeting" ] || exit 2
101+
[ "$(cat)" = "zeroshot release smoke" ] || exit 3
102+
[ "$(cat greeting.txt)" = "zeroshot release smoke" ] || exit 4
103+
`,
104+
{ mode: 0o755 }
105+
);
106+
try {
107+
distribution.smokeExecutable(binaryPath, 'RUST_BINARY_SMOKE_FAILED');
108+
} finally {
109+
fs.rmSync(directory, { recursive: true, force: true });
110+
}
111+
});
112+
});
113+
92114
function registerVersionCouplingTests() {
93115
it('fails a release version mismatch with the named error and both versions', function () {
94116
const cargoToml = '[package]\nname = "zeroshot-rust"\nversion = "1.2.2"\n';

0 commit comments

Comments
 (0)