-
Notifications
You must be signed in to change notification settings - Fork 1
ts(B-0086): port 2 scripts (.sh→.ts) — slice 11 of TS/Bun migration #884
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
AceHack
merged 10 commits into
main
from
lane-b/ts-bun-slice-11-dv2-frontmatter-backfill-2026-04-30
Apr 30, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
01be9a8
ts(slice-11, wip 1/N): port backfill_dv2_frontmatter (.sh→.ts)
AceHack db2efa1
ts(slice-11, wip 2/N): port audit-packages (.sh→.ts)
AceHack 744f173
trajectory(ts-bun): slice 11 audit substrate + RESUME tracker
AceHack ac6c43f
review(slice-11): address PR #884 CodeQL TOCTOU findings
AceHack 5baf773
review(slice-11): restore atomic rewrite per Codex P2
AceHack e02f47d
review(slice-11): address PR #884 round-3 threads
AceHack c9a4933
review(slice-11): audit-packages repoRoot via import.meta.url per Cod…
AceHack dfbd6dc
review(slice-11): defensive rename fallback per Codex P0
AceHack 3462fe3
review(slice-11): preserve-original-on-failure + fail-on-empty-parse …
AceHack eb76aa4
review(slice-11): fix RESUME milestone math per Copilot
AceHack 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 bun | ||
| // audit-packages.ts — checks every Directory.Packages.props entry | ||
| // against the NuGet feed via `dotnet package search`. | ||
| // | ||
| // TypeScript+Bun port of audit-packages.sh, slice 11 of the TS+Bun | ||
| // migration. See docs/best-practices/repo-scripting.md. | ||
| // | ||
| // Network-dependent: shells out to `dotnet package search <id> | ||
| // --exact-match` per package; non-deterministic without a NuGet | ||
| // snapshot. Equivalence-test via the no-network failure path | ||
| // (each `latest` falls back to `?`). | ||
| // | ||
| // Usage: | ||
| // bun tools/audit-packages.ts | ||
| // | ||
| // Exit codes: | ||
| // 0 all queryable packages on latest | ||
| // 1 one or more packages have a bump available | ||
|
|
||
| import { readFileSync } from "node:fs"; | ||
| import { dirname, join, resolve } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| type ExitCode = 0 | 1; | ||
|
|
||
| const SPAWN_MAX_BUFFER = 64 * 1024 * 1024; | ||
|
|
||
| const PACKAGE_RE = /PackageVersion Include="([^"]+)" Version="([^"]+)"/g; | ||
|
|
||
| interface PackageEntry { | ||
| readonly id: string; | ||
| readonly pinned: string; | ||
| } | ||
|
|
||
| function repoRoot(): string { | ||
| // Match bash original: REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)". | ||
| // Bash resolves the script's path, walks up one (tools/.. → repo root), | ||
| // and cds. The TS port mirrors this via import.meta.url so the script | ||
| // works regardless of caller cwd, the same as the bash behavior. | ||
| const scriptPath = fileURLToPath(import.meta.url); | ||
| return resolve(dirname(scriptPath), ".."); | ||
| } | ||
|
|
||
| function parsePackages(content: string): readonly PackageEntry[] { | ||
| const out: PackageEntry[] = []; | ||
| PACKAGE_RE.lastIndex = 0; | ||
| let m: RegExpExecArray | null = PACKAGE_RE.exec(content); | ||
| while (m !== null) { | ||
| out.push({ id: m[1] ?? "", pinned: m[2] ?? "" }); | ||
| m = PACKAGE_RE.exec(content); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| function queryLatest(pkgId: string): string { | ||
| const args = ["package", "search", pkgId, "--exact-match"]; | ||
| // eslint-disable-next-line sonarjs/no-os-command-from-path | ||
| const result = spawnSync("dotnet", args, { | ||
| encoding: "utf8", | ||
| maxBuffer: SPAWN_MAX_BUFFER, | ||
| }); | ||
| if (result.status !== 0) return ""; | ||
| let last = ""; | ||
| for (const line of result.stdout.split("\n")) { | ||
| const cols = line.split("|").map((c) => c.trim()); | ||
| const col2 = cols[1] ?? ""; | ||
| if (col2 !== pkgId) continue; | ||
| last = cols[2] ?? ""; | ||
| } | ||
| return last; | ||
| } | ||
|
|
||
| function pad(s: string, width: number): string { | ||
| return s.length >= width ? s : s + " ".repeat(width - s.length); | ||
| } | ||
|
|
||
| interface Report { | ||
| readonly id: string; | ||
| readonly pinned: string; | ||
| readonly latest: string; | ||
| readonly marker: string; | ||
| } | ||
|
|
||
| function classify( | ||
| pinned: string, | ||
| latest: string, | ||
| ): { marker: string; failed: boolean } { | ||
| if (latest === pinned) return { marker: "✓ up-to-date", failed: false }; | ||
| if (latest === "?") return { marker: "? couldn't query", failed: false }; | ||
| return { marker: "⚠ bump available", failed: true }; | ||
| } | ||
|
|
||
| export function main(): ExitCode { | ||
| const root = repoRoot(); | ||
| const propsPath = join(root, "Directory.Packages.props"); | ||
| let content: string; | ||
| try { | ||
| content = readFileSync(propsPath, "utf8"); | ||
| } catch { | ||
| process.stderr.write(`error: cannot read ${propsPath}\n`); | ||
| return 1; | ||
| } | ||
|
AceHack marked this conversation as resolved.
|
||
| const packages = parsePackages(content); | ||
|
AceHack marked this conversation as resolved.
|
||
|
|
||
| // If parsing yields zero entries on a non-empty Directory.Packages.props, | ||
| // the regex has likely drifted from the file format — silent success | ||
| // would hide real audit failure (Codex P2). Fail with a clear message. | ||
| if (packages.length === 0) { | ||
| process.stderr.write( | ||
| `error: parsed 0 PackageVersion entries from ${propsPath} — regex may be stale relative to file format\n`, | ||
| ); | ||
| return 1; | ||
| } | ||
|
|
||
| process.stdout.write("=== Dbsp package audit ===\n"); | ||
| process.stdout.write( | ||
| `${pad("Package", 35)} ${pad("Pinned", 15)} ${pad("Latest", 15)} Status\n`, | ||
| ); | ||
| process.stdout.write( | ||
| `${pad("-------", 35)} ${pad("------", 15)} ${pad("------", 15)} ------\n`, | ||
| ); | ||
|
AceHack marked this conversation as resolved.
|
||
|
|
||
| let failed = false; | ||
| const reports: Report[] = []; | ||
| for (const pkg of packages) { | ||
| const latest = queryLatest(pkg.id); | ||
| const display = latest === "" ? "?" : latest; | ||
| const { marker, failed: thisFailed } = classify(pkg.pinned, display); | ||
| if (thisFailed) failed = true; | ||
| reports.push({ id: pkg.id, pinned: pkg.pinned, latest: display, marker }); | ||
| } | ||
|
|
||
| for (const r of reports) { | ||
| process.stdout.write( | ||
| `${pad(r.id, 35)} ${pad(r.pinned, 15)} ${pad(r.latest, 15)} ${r.marker}\n`, | ||
| ); | ||
| } | ||
|
|
||
| process.stdout.write("\n"); | ||
| if (!failed) { | ||
| process.stdout.write("✓ All queryable packages on latest.\n"); | ||
| return 0; | ||
| } | ||
| process.stdout.write( | ||
| "⚠ Bumps available — update Directory.Packages.props and re-run tests.\n", | ||
| ); | ||
| return 1; | ||
| } | ||
|
|
||
| if (import.meta.main) { | ||
| process.exit(main()); | ||
| } | ||
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.