forked from abhigyanpatwari/GitNexus
-
Notifications
You must be signed in to change notification settings - Fork 0
build(release): pin and prove LadybugDB 0.18.1 #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9c15016
build(release): pin and prove LadybugDB 0.18.1
acefe4a
test(release): exercise verifier on Windows CI
54b85fb
test(release): preserve packaged vendor invariants
c92f914
test(release): bind verifier to Ladybug pin
1537700
fix(release): bound packaged CLI proof
da90a44
fix(release): hard-kill timed out CLI proof
fbe68ab
test(release): prove hard CLI deadline
eb8cd1d
fix(release): verify CLI without shell wrappers
4c0966e
test(release): preserve launcher and recovery contracts
307afda
test(release): bind launcher to package entry
197dbae
fix(release): classify package proof failures portably
e1e04dd
fix(release): verify shipped grammar tree
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { createHash } from 'node:crypto'; | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { createRequire } from 'node:module'; | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const EXPECTED_LADYBUG_VERSION = '0.18.1'; | ||
| const ARGUMENT_KEYS = new Set(['asset', 'checksums', 'prefix', 'expected-version']); | ||
| const USAGE = | ||
| 'usage: verify-electric-package.mjs --asset <tarball> --checksums <file> --prefix <dir> --expected-version <version>'; | ||
|
|
||
| function parseArgs(argv) { | ||
| const values = {}; | ||
| for (let index = 0; index < argv.length; index += 2) { | ||
|
100yenadmin marked this conversation as resolved.
|
||
| const key = argv[index]; | ||
| const value = argv[index + 1]; | ||
| if (!key?.startsWith('--')) | ||
| throw new Error(`unexpected argument: ${key ?? '<missing>'}\n${USAGE}`); | ||
| const name = key.slice(2); | ||
| if (!ARGUMENT_KEYS.has(name)) throw new Error(`unexpected argument: ${key}\n${USAGE}`); | ||
| if (Object.hasOwn(values, name)) throw new Error(`duplicate argument: ${key}`); | ||
| if (!value || value.startsWith('--')) throw new Error(`missing value for ${key}\n${USAGE}`); | ||
| values[name] = value; | ||
| } | ||
| for (const key of ARGUMENT_KEYS) { | ||
| if (!values[key]) throw new Error(`missing --${key}`); | ||
| } | ||
| return values; | ||
| } | ||
|
|
||
| function requireRegularFile(file) { | ||
| const stat = fs.lstatSync(file); | ||
| if (!stat.isFile() || stat.size <= 0) | ||
| throw new Error(`expected a non-empty regular file: ${file}`); | ||
| } | ||
|
|
||
| function verifyChecksum(assetPath, checksumPath) { | ||
| requireRegularFile(assetPath); | ||
| requireRegularFile(checksumPath); | ||
| const filename = path.basename(assetPath); | ||
| const matches = fs | ||
| .readFileSync(checksumPath, 'utf8') | ||
| .split(/\r?\n/u) | ||
| .filter(Boolean) | ||
| .map((line) => line.match(/^([0-9a-f]{64})\s+\*?(.+)$/u)) | ||
|
100yenadmin marked this conversation as resolved.
|
||
| .filter((match) => match?.[2] === filename); | ||
| if (matches.length !== 1) { | ||
| throw new Error(`SHA256SUMS must contain exactly one lowercase SHA-256 entry for ${filename}`); | ||
| } | ||
| const actual = createHash('sha256').update(fs.readFileSync(assetPath)).digest('hex'); | ||
| if (actual !== matches[0][1]) throw new Error(`SHA-256 mismatch for ${filename}`); | ||
| return actual; | ||
| } | ||
|
|
||
| function locateInstalledPackage(prefix) { | ||
| const candidates = [ | ||
| path.join(prefix, 'lib', 'node_modules', 'gitnexus'), | ||
| path.join(prefix, 'node_modules', 'gitnexus'), | ||
| ]; | ||
| const installed = candidates.find((candidate) => | ||
| fs.existsSync(path.join(candidate, 'package.json')), | ||
| ); | ||
| if (!installed) throw new Error(`installed gitnexus package not found under ${prefix}`); | ||
| return installed; | ||
| } | ||
|
|
||
| function runCli(prefix, args) { | ||
|
100yenadmin marked this conversation as resolved.
Outdated
|
||
| const executable = | ||
| process.platform === 'win32' | ||
| ? path.join(prefix, 'gitnexus.cmd') | ||
| : path.join(prefix, 'bin', 'gitnexus'); | ||
| const result = spawnSync(executable, args, { | ||
| encoding: 'utf8', | ||
| env: { ...process.env, NO_COLOR: '1' }, | ||
| shell: process.platform === 'win32', | ||
| }); | ||
| if (result.error || result.status !== 0) { | ||
| throw new Error( | ||
| `gitnexus ${args.join(' ')} failed: ${result.error?.message ?? result.stderr.trim()}`, | ||
| ); | ||
| } | ||
| return result.stdout.trim(); | ||
| } | ||
|
|
||
| export function verifyElectricPackage({ asset, checksums, prefix, expectedVersion }) { | ||
| const digest = verifyChecksum(asset, checksums); | ||
| const installed = locateInstalledPackage(prefix); | ||
| const packageJson = JSON.parse(fs.readFileSync(path.join(installed, 'package.json'), 'utf8')); | ||
| if (packageJson.name !== 'gitnexus' || packageJson.version !== expectedVersion) { | ||
| throw new Error( | ||
| `installed package identity is ${packageJson.name}@${packageJson.version}, expected gitnexus@${expectedVersion}`, | ||
| ); | ||
| } | ||
|
|
||
| const ladybugPackagePath = path.join( | ||
| installed, | ||
| 'node_modules', | ||
| '@ladybugdb', | ||
| 'core', | ||
| 'package.json', | ||
| ); | ||
| const ladybugPackage = JSON.parse(fs.readFileSync(ladybugPackagePath, 'utf8')); | ||
| if (ladybugPackage.version !== EXPECTED_LADYBUG_VERSION) { | ||
| throw new Error( | ||
| `installed @ladybugdb/core is ${ladybugPackage.version}, expected ${EXPECTED_LADYBUG_VERSION}`, | ||
| ); | ||
| } | ||
|
|
||
| const requireFromPackage = createRequire(path.join(installed, 'package.json')); | ||
|
100yenadmin marked this conversation as resolved.
|
||
| const loaded = requireFromPackage('@ladybugdb/core'); | ||
| const api = loaded?.default ?? loaded; | ||
| if (typeof api?.Database !== 'function' || typeof api?.Connection !== 'function') { | ||
| throw new Error('@ladybugdb/core loaded without Database and Connection constructors'); | ||
| } | ||
|
|
||
| const versionOutput = runCli(prefix, ['--version']); | ||
|
100yenadmin marked this conversation as resolved.
|
||
| if (versionOutput !== expectedVersion) { | ||
| throw new Error(`packaged CLI version is ${versionOutput}, expected ${expectedVersion}`); | ||
| } | ||
| runCli(prefix, ['--help']); | ||
| runCli(prefix, ['mcp', '--help']); | ||
|
|
||
| return { | ||
| package: `gitnexus@${expectedVersion}`, | ||
| ladybug: `@ladybugdb/core@${EXPECTED_LADYBUG_VERSION}`, | ||
| sha256: digest, | ||
| nativeImport: 'ok', | ||
| cli: 'ok', | ||
| mcpHelp: 'ok', | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| process.argv[1] && | ||
| path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url)) | ||
| ) { | ||
| try { | ||
| const args = parseArgs(process.argv.slice(2)); | ||
| const result = verifyElectricPackage({ | ||
| asset: path.resolve(args.asset), | ||
| checksums: path.resolve(args.checksums), | ||
| prefix: path.resolve(args.prefix), | ||
| expectedVersion: args['expected-version'], | ||
| }); | ||
| process.stdout.write(`${JSON.stringify(result)}\n`); | ||
| } catch (error) { | ||
| process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`); | ||
| process.exitCode = 1; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.