A service in front of a hub needs four things: start a flow, follow it, read what a detached run produced, and decide approvals. This is that surface, plus the part a gateway cannot test without: a fake hub that speaks the same service from the same .proto files and can be scripted into every failure a real hub produces. Errors carry the hub's own class (chain-error-kind), a coarse family, and reachedHub, which separates a refused connection from a hub that reports a dependency as down. Both arrive as gRPC UNAVAILABLE, and a gateway that shows 'service not reachable' for the second one lies to its users. The .proto files are carried verbatim and loaded at runtime, so no generated code can drift from the contract; two guards hold the copies in place, and a skew suite runs the same client against a real hub binary. 32 hermetic tests plus 4 against a real hub. Signed-off-by: Dr. Stefan Flemming <sf@flemming.it>
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// Refresh the verbatim `chain.v1` copies from the platform repo and
|
|
// record their hashes.
|
|
//
|
|
// Usage: node scripts/sync-proto.mjs [path-to-platform-repo]
|
|
// Default: ../fai_chain, or $CHAIN_PLATFORM_REPO.
|
|
|
|
import { createHash } from 'node:crypto';
|
|
import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { dirname, join, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const root = resolve(here, '..');
|
|
const files = [
|
|
'chain/v1/common.proto',
|
|
'chain/v1/hub.proto',
|
|
'chain/v1/module.proto',
|
|
'chain/v1/federation.proto',
|
|
];
|
|
|
|
const platform = resolve(
|
|
process.argv[2] ?? process.env.CHAIN_PLATFORM_REPO ?? join(root, '..', 'fai_chain'),
|
|
);
|
|
if (!existsSync(join(platform, 'proto', 'chain', 'v1', 'hub.proto'))) {
|
|
console.error(`no proto/chain/v1 under ${platform}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const lines = [];
|
|
for (const file of files) {
|
|
const from = join(platform, 'proto', file);
|
|
const to = join(root, 'proto', file);
|
|
copyFileSync(from, to);
|
|
const hash = createHash('sha256').update(readFileSync(to)).digest('hex');
|
|
lines.push(`${hash} ${file}`);
|
|
console.log(`${file} <- ${from}`);
|
|
}
|
|
writeFileSync(join(root, 'proto', 'CHECKSUMS'), `${lines.join('\n')}\n`, 'utf8');
|
|
console.log('proto/CHECKSUMS written');
|