GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — OpenAgentPack/scripts/release/smoke-packed.ts at main · modelstudioai/OpenAgentPack

Expand file tree

/

smoke-packed.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
184 lines (167 loc) · 7.08 KB
/

smoke-packed.ts

Copy path

File metadata and controls

184 lines (167 loc) · 7.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* Pack the exact publish manifests, install them as an external npm consumer,
* then exercise every public SDK entry point plus the CLI and Playground bins.
*
* `--sdk-only` installs just the SDK, including its Node-only project subpaths.
* CI uses this below the CLI/Playground Node floor to enforce Node >=18.17.0.
*/
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { createServer } from "node:net";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { projectSdkSmokeSource } from "./project-sdk-smoke.ts";
import {
PACKAGES,
restoreLicense,
restorePackageJson,
rewriteManifestForPublish,
stageLicense,
workspaceVersions,
} from "./publish.ts";
const root = resolve(import.meta.dirname, "../..");
export function isSdkOnly(argv: readonly string[]): boolean {
return argv.includes("--sdk-only");
}
export function smokePackages(sdkOnly: boolean): readonly (typeof PACKAGES)[number][] {
return sdkOnly ? PACKAGES.filter((pkg) => pkg === "sdk") : PACKAGES;
}
type PackedPackage = { filename: string };
export function packedFilename(raw: string, pkg: string): string {
const parsed = JSON.parse(raw) as PackedPackage[] | Record<string, PackedPackage>;
const packed = Array.isArray(parsed) ? parsed : Object.values(parsed);
if (packed.length !== 1 || !packed[0]?.filename) throw new Error(`Unexpected npm pack output for ${pkg}`);
return packed[0].filename;
}
function run(command: string[], cwd: string, stdout: "inherit" | "pipe" = "inherit"): string {
const result = Bun.spawnSync(command, { cwd, stdout, stderr: "inherit" });
if (result.exitCode !== 0) throw new Error(`Command failed (${result.exitCode}): ${command.join(" ")}`);
return stdout === "pipe" ? (result.stdout?.toString().trim() ?? "") : "";
}
function packPackages(destination: string, packages: readonly (typeof PACKAGES)[number][]): string[] {
const versions = workspaceVersions();
return packages.map((pkg) => {
const pkgDir = join(root, "packages", pkg);
let originalLicense: string | undefined;
let originalManifest: string | undefined;
let licenseStaged = false;
try {
originalLicense = stageLicense(pkgDir);
licenseStaged = true;
originalManifest = rewriteManifestForPublish(pkgDir, versions);
const raw = run(["npm", "pack", "--json", "--pack-destination", destination], pkgDir, "pipe");
return join(destination, packedFilename(raw, pkg));
} finally {
if (originalManifest !== undefined) restorePackageJson(pkgDir, originalManifest);
if (licenseStaged) restoreLicense(pkgDir, originalLicense);
}
});
}
async function availablePort(): Promise<number> {
return await new Promise((resolvePort, reject) => {
const server = createServer();
server.once("error", reject);
server.listen(0, "127.0.0.1", () => {
const address = server.address();
if (!address || typeof address === "string") return reject(new Error("Failed to allocate a smoke-test port"));
server.close((error) => (error ? reject(error) : resolvePort(address.port)));
});
});
}
async function smokePlayground(consumer: string): Promise<void> {
const port = await availablePort();
const entry = join(consumer, "node_modules/@openagentpack/playground/dist/bin/playground.js");
const child = Bun.spawn(["node", entry], {
cwd: consumer,
env: { ...process.env, PORT: String(port) },
stdout: "pipe",
stderr: "pipe",
});
try {
for (let attempt = 0; attempt < 50; attempt++) {
if (child.exitCode !== null) {
throw new Error(`Packed Playground exited before becoming ready: ${await new Response(child.stderr).text()}`);
}
try {
const response = await fetch(`http://127.0.0.1:${port}/`);
const html = await response.text();
if (response.ok && html.includes('name="agents-runtime" content="playground"')) {
const assets = [...html.matchAll(/(?:src|href)="(\/assets\/[^"]+)"/g)].map((match) => match[1]);
if (assets.length === 0) throw new Error("Packed Playground HTML references no built assets");
for (const asset of assets) {
const assetResponse = await fetch(`http://127.0.0.1:${port}${asset}`);
if (!assetResponse.ok) throw new Error(`Packed Playground asset is unavailable: ${asset}`);
}
return;
}
} catch {
// The child has not bound its port yet.
}
await Bun.sleep(100);
}
throw new Error("Packed Playground did not become ready within 5 seconds");
} finally {
child.kill();
await child.exited;
}
}
async function main(): Promise<void> {
const sdkOnly = isSdkOnly(process.argv.slice(2));
const packages = smokePackages(sdkOnly);
const temporaryRoot = mkdtempSync(join(tmpdir(), "openagentpack-consumer-"));
try {
const tarballsDir = join(temporaryRoot, "tarballs");
const consumer = join(temporaryRoot, "consumer");
mkdirSync(tarballsDir);
mkdirSync(consumer);
writeFileSync(join(consumer, "package.json"), '{"name":"agents-package-smoke","private":true,"type":"module"}\n');
const tarballs = packPackages(tarballsDir, packages);
run(
[
"npm",
"install",
"--engine-strict",
"--ignore-scripts",
"--no-audit",
"--no-fund",
"--no-package-lock",
...tarballs,
],
consumer,
);
for (const pkg of packages) {
const license = readFileSync(join(consumer, `node_modules/@openagentpack/${pkg}/LICENSE`), "utf8");
if (license !== readFileSync(join(root, "LICENSE"), "utf8")) {
throw new Error(`${pkg} package is missing the repository license`);
}
}
run(
[
"node",
"--input-type=module",
"--eval",
'const sdk = await import("@openagentpack/sdk"); for (const method of ["listSessionThreads", "listSessionThreadEvents"]) { if (typeof sdk[method] !== "function") throw new Error(method + " export missing"); } await import("@openagentpack/sdk/session-events"); await import("@openagentpack/sdk/scan-lifecycle"); await import("@openagentpack/sdk/file-lifecycle"); const versions = await import("@openagentpack/sdk/project-versions"); const workspace = await import("@openagentpack/sdk/project-workspace"); if (typeof versions.createProjectVersionService !== "function") throw new Error("project-versions export missing"); if (typeof workspace.previewProjectBuild !== "function") throw new Error("project-workspace export missing");',
],
consumer,
);
run(["node", "--input-type=module", "--eval", projectSdkSmokeSource], consumer);
if (!sdkOnly) {
const expectedVersion = JSON.parse(readFileSync(join(root, "packages/cli/package.json"), "utf8")) as {
version: string;
};
const cliVersion = run(
["node", join(consumer, "node_modules/@openagentpack/cli/dist/bin/agents.js"), "--version"],
consumer,
"pipe",
);
if (cliVersion !== expectedVersion.version) {
throw new Error(`Packed CLI version mismatch: expected ${expectedVersion.version}, received ${cliVersion}`);
}
await smokePlayground(consumer);
}
const nodeVersion = run(["node", "--version"], consumer, "pipe");
console.log(`✓ Packed ${sdkOnly ? "library packages install" : "packages install"} and run under ${nodeVersion}`);
} finally {
rmSync(temporaryRoot, { recursive: true, force: true });
}
}
if (import.meta.main) await main();
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.