From 7fdf1677f511b5d7b3291c8bcc29cd622252d666 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 16 Sep 2026 17:08:26 +0530 Subject: [PATCH 1/6] chore(account): add the publish files allowlist --- packages/account/package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/account/package.json b/packages/account/package.json index c320a0ea6cc..b780fc57102 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -5,6 +5,11 @@ "description": "Shared account layer: a framework-free session core that exchanges a signed-in identity for the workspace-scoped Cloud JWT with valid-on-read freshness, the package-owned Firebase identity entry, and an optional Vue subpath for the shared sign-in pieces", "keywords": [], "license": "MIT", + "files": [ + "src", + "!src/**/*.test.ts", + "!src/**/__fixtures__" + ], "type": "module", "exports": { "./boundedOperation": "./src/core/boundedOperation.ts", From 21abb9ed6186610369fa74be8697949be4e5655d Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 16 Sep 2026 17:14:29 +0530 Subject: [PATCH 2/6] test(account): packed-tarball consumer smoke test --- packages/account/package.json | 3 +- packages/account/scripts/smokePack.ts | 247 +++++++++++++++++++++++++ packages/account/scripts/tsconfig.json | 9 + 3 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 packages/account/scripts/smokePack.ts create mode 100644 packages/account/scripts/tsconfig.json diff --git a/packages/account/package.json b/packages/account/package.json index b780fc57102..3ae78441e32 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -38,8 +38,9 @@ }, "scripts": { "lint": "oxlint src --type-aware && eslint src", + "smoke:pack": "tsx scripts/smokePack.ts", "test": "vitest run", - "typecheck": "vue-tsc --noEmit" + "typecheck": "vue-tsc --noEmit && vue-tsc --noEmit --project scripts/tsconfig.json" }, "dependencies": { "@comfyorg/ingest-types": "workspace:*", diff --git a/packages/account/scripts/smokePack.ts b/packages/account/scripts/smokePack.ts new file mode 100644 index 00000000000..d68dc56e25b --- /dev/null +++ b/packages/account/scripts/smokePack.ts @@ -0,0 +1,247 @@ +/** + * Packs @comfyorg/account with `pnpm pack`, installs the tarball into a + * throwaway npm project alongside the declared peers, and imports every + * export entry from there: the consumer path where an unrewritten + * `catalog:` specifier or an export target missing from `files` first fails. + * + * Workspace siblings are not on npm yet, so they are packed too and pinned + * through npm `overrides`; drop that once they are published. + */ +import { execFileSync } from 'node:child_process' +import { + existsSync, + mkdirSync, + mkdtempSync, + readdirSync, + readFileSync, + rmSync, + writeFileSync +} from 'node:fs' +import { tmpdir } from 'node:os' +import { join, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' + +interface Manifest { + readonly name: string + readonly version: string + readonly exports: Readonly> + readonly dependencies?: Readonly> + readonly peerDependencies?: Readonly> +} + +interface PackResult { + readonly filename: string + readonly files: ReadonlyArray<{ readonly path: string }> +} + +const packageDir = fileURLToPath(new URL('..', import.meta.url)) +const workspaceRoot = resolve(packageDir, '..', '..') +const packagesDir = resolve(packageDir, '..') +const keep = process.argv.includes('--keep') + +const WORKSPACE_ONLY_SPECIFIER = /^(catalog|workspace):/ +const NON_PUBLIC_FILE = /(\.test\.ts$|(^|\/)__fixtures__\/)/ + +function run(command: string, args: string[], cwd: string): string { + return execFileSync(command, args, { + cwd, + encoding: 'utf8', + stdio: ['ignore', 'pipe', 'inherit'] + }) +} + +function readManifest(dir: string): Manifest { + return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) +} + +function workspacePackageDirs(): Map { + return new Map( + readdirSync(packagesDir) + .map((entry) => join(packagesDir, entry)) + .filter((dir) => existsSync(join(dir, 'package.json'))) + .map((dir) => [readManifest(dir).name, dir]) + ) +} + +function workspaceDependencyClosure( + dir: string, + dirsByName: Map, + closure = new Map() +): Map { + for (const [name, specifier] of Object.entries( + readManifest(dir).dependencies ?? {} + )) { + if (!specifier.startsWith('workspace:') || closure.has(name)) continue + const depDir = dirsByName.get(name) + if (!depDir) throw new Error(`workspace dependency ${name} not found`) + closure.set(name, depDir) + workspaceDependencyClosure(depDir, dirsByName, closure) + } + return closure +} + +function pack(dir: string, destination: string): PackResult { + return JSON.parse( + run('pnpm', ['pack', '--json', '--pack-destination', destination], dir) + ) +} + +function packedManifest(tarball: string): Manifest { + return JSON.parse( + run('tar', ['-xzOf', tarball, 'package/package.json'], packageDir) + ) +} + +function log(line: string): void { + process.stdout.write(`${line}\n`) +} + +function fail(message: string): never { + throw new Error(message) +} + +function assertPublishable(source: Manifest, packed: PackResult): void { + const shipped = new Set(packed.files.map((file) => file.path)) + const missingTargets = Object.values(source.exports) + .map((target) => target.replace(/^\.\//, '')) + .filter((target) => !shipped.has(target)) + if (missingTargets.length > 0) { + fail( + `export targets missing from the tarball:\n${missingTargets.join('\n')}` + ) + } + const nonPublic = [...shipped].filter((path) => NON_PUBLIC_FILE.test(path)) + if (nonPublic.length > 0) { + fail(`test-only files in the tarball:\n${nonPublic.join('\n')}`) + } + const manifest = packedManifest(packed.filename) + const unrewritten = Object.entries({ + ...manifest.dependencies, + ...manifest.peerDependencies + }).filter(([, specifier]) => WORKSPACE_ONLY_SPECIFIER.test(specifier)) + if (unrewritten.length > 0) { + fail( + `specifiers only pnpm can rewrite survived packing:\n${unrewritten + .map(([name, specifier]) => `${name}: ${specifier}`) + .join('\n')}` + ) + } + log(`packed ${shipped.size} files, specifiers rewritten`) +} + +const CONSUMER_SOURCE = ` +import { existsSync, readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { createLazyIdentity } from '@comfyorg/account/lazyIdentity' +import type { AccountUser } from '@comfyorg/account/session' +import { createSessionClient } from '@comfyorg/account/session' +import { createTestIdentity } from '@comfyorg/account/testing' + +const identity = createTestIdentity({ + onUserChanged: (callback) => { + callback(null) + return () => {} + } +}) +const lazyIdentity = createLazyIdentity(async () => identity) +const memory = new Map() +const client = createSessionClient( + { + exchangeUrl: 'https://example.invalid/api/auth/token', + storage: { + read: () => memory.get('credential') ?? null, + write: (value) => memory.set('credential', value), + clear: () => memory.delete('credential') + } + }, + lazyIdentity +) +const beforeActivation = client.getSnapshot().phase +await lazyIdentity.activate() +const afterActivation = client.getSnapshot().phase +client.dispose() +if (beforeActivation !== 'pending' || afterActivation !== 'signed-out') { + throw new Error( + \`session client phases \${beforeActivation} -> \${afterActivation}\` + ) +} +console.log(\`session client: \${beforeActivation} -> \${afterActivation}\`) + +const subpaths: string[] = JSON.parse(readFileSync('entries.json', 'utf8')) +for (const subpath of subpaths) { + const specifier = subpath.replace(/^\\./, '@comfyorg/account') + const target = fileURLToPath(import.meta.resolve(specifier)) + if (!existsSync(target)) throw new Error(\`\${specifier} resolves to a missing file\`) + if (target.endsWith('.vue')) { + console.log(\`\${specifier}: resolved (Vue SFC, needs a bundler to load)\`) + continue + } + await import(specifier) + console.log(\`\${specifier}: imported\`) +} +` + +function main(): void { + const source = readManifest(packageDir) + const consumerDir = mkdtempSync(join(tmpdir(), 'comfyorg-account-smoke-')) + const tarballDir = join(consumerDir, 'tarballs') + mkdirSync(tarballDir) + try { + const packed = pack(packageDir, tarballDir) + assertPublishable(source, packed) + + const siblings = workspaceDependencyClosure( + packageDir, + workspacePackageDirs() + ) + const overrides = Object.fromEntries( + [...siblings].map(([name, dir]) => [ + name, + `file:${pack(dir, tarballDir).filename}` + ]) + ) + const peers = packedManifest(packed.filename).peerDependencies ?? {} + writeFileSync( + join(consumerDir, 'package.json'), + JSON.stringify( + { + name: 'comfyorg-account-smoke', + private: true, + type: 'module', + dependencies: { + [source.name]: `file:${packed.filename}`, + ...peers + }, + overrides + }, + null, + 2 + ) + ) + log(`installing into ${consumerDir}`) + run( + 'npm', + ['install', '--no-audit', '--no-fund', '--loglevel=error'], + consumerDir + ) + + writeFileSync( + join(consumerDir, 'entries.json'), + JSON.stringify(Object.keys(source.exports)) + ) + writeFileSync(join(consumerDir, 'consumer.ts'), CONSUMER_SOURCE) + const tsx = join(workspaceRoot, 'node_modules', '.bin', 'tsx') + process.stdout.write(run(tsx, ['consumer.ts'], consumerDir)) + log('packed tarball smoke test passed') + } finally { + if (keep) log(`kept ${consumerDir}`) + else rmSync(consumerDir, { recursive: true, force: true }) + } +} + +try { + main() +} catch (error) { + console.error(error instanceof Error ? error.message : error) + process.exitCode = 1 +} diff --git a/packages/account/scripts/tsconfig.json b/packages/account/scripts/tsconfig.json new file mode 100644 index 00000000000..33482f082fb --- /dev/null +++ b/packages/account/scripts/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "incremental": false, + "types": ["node"] + }, + "include": ["**/*.ts"] +} From e1fc5b1acd317ee28b8614eadb1a328846f9ce9b Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 16 Sep 2026 17:15:33 +0530 Subject: [PATCH 3/6] chore(account): declare public publish access --- packages/account/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/account/package.json b/packages/account/package.json index 3ae78441e32..94897cf3798 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -36,6 +36,9 @@ "./telemetry": "./src/telemetry.ts", "./webviewDetection": "./src/webviewDetection.ts" }, + "publishConfig": { + "access": "public" + }, "scripts": { "lint": "oxlint src --type-aware && eslint src", "smoke:pack": "tsx scripts/smokePack.ts", From e106cf52094c5ae0917f0393b239e8966488bc2c Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 16 Sep 2026 17:28:42 +0530 Subject: [PATCH 4/6] chore(account): export the package manifest --- packages/account/package.json | 3 ++- packages/account/scripts/smokePack.ts | 15 +++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/account/package.json b/packages/account/package.json index 94897cf3798..6b6e60c0c16 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -34,7 +34,8 @@ "./provisioning": "./src/provisioning.ts", "./redirect": "./src/redirect.ts", "./telemetry": "./src/telemetry.ts", - "./webviewDetection": "./src/webviewDetection.ts" + "./webviewDetection": "./src/webviewDetection.ts", + "./package.json": "./package.json" }, "publishConfig": { "access": "public" diff --git a/packages/account/scripts/smokePack.ts b/packages/account/scripts/smokePack.ts index d68dc56e25b..d571b876c3a 100644 --- a/packages/account/scripts/smokePack.ts +++ b/packages/account/scripts/smokePack.ts @@ -130,7 +130,7 @@ function assertPublishable(source: Manifest, packed: PackResult): void { } const CONSUMER_SOURCE = ` -import { existsSync, readFileSync } from 'node:fs' +import { existsSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { createLazyIdentity } from '@comfyorg/account/lazyIdentity' import type { AccountUser } from '@comfyorg/account/session' @@ -167,8 +167,10 @@ if (beforeActivation !== 'pending' || afterActivation !== 'signed-out') { } console.log(\`session client: \${beforeActivation} -> \${afterActivation}\`) -const subpaths: string[] = JSON.parse(readFileSync('entries.json', 'utf8')) -for (const subpath of subpaths) { +const { default: manifest } = await import('@comfyorg/account/package.json', { + with: { type: 'json' } +}) +for (const subpath of Object.keys(manifest.exports)) { const specifier = subpath.replace(/^\\./, '@comfyorg/account') const target = fileURLToPath(import.meta.resolve(specifier)) if (!existsSync(target)) throw new Error(\`\${specifier} resolves to a missing file\`) @@ -176,7 +178,8 @@ for (const subpath of subpaths) { console.log(\`\${specifier}: resolved (Vue SFC, needs a bundler to load)\`) continue } - await import(specifier) + if (target.endsWith('.json')) await import(specifier, { with: { type: 'json' } }) + else await import(specifier) console.log(\`\${specifier}: imported\`) } ` @@ -225,10 +228,6 @@ function main(): void { consumerDir ) - writeFileSync( - join(consumerDir, 'entries.json'), - JSON.stringify(Object.keys(source.exports)) - ) writeFileSync(join(consumerDir, 'consumer.ts'), CONSUMER_SOURCE) const tsx = join(workspaceRoot, 'node_modules', '.bin', 'tsx') process.stdout.write(run(tsx, ['consumer.ts'], consumerDir)) From 0419d3837fb352840e49668f477f4a56b154bf16 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 16 Sep 2026 20:35:34 +0530 Subject: [PATCH 5/6] refactor(account): flatten the workspace dependency closure walk --- packages/account/scripts/smokePack.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/account/scripts/smokePack.ts b/packages/account/scripts/smokePack.ts index d571b876c3a..f45ae64946d 100644 --- a/packages/account/scripts/smokePack.ts +++ b/packages/account/scripts/smokePack.ts @@ -63,19 +63,28 @@ function workspacePackageDirs(): Map { ) } +function workspaceDependencies( + dir: string, + dirsByName: Map +): Array<[string, string]> { + return Object.entries(readManifest(dir).dependencies ?? {}) + .filter(([, specifier]) => specifier.startsWith('workspace:')) + .map(([name]) => [ + name, + dirsByName.get(name) ?? fail(`workspace dependency ${name} not found`) + ]) +} + function workspaceDependencyClosure( dir: string, - dirsByName: Map, - closure = new Map() + dirsByName: Map ): Map { - for (const [name, specifier] of Object.entries( - readManifest(dir).dependencies ?? {} - )) { - if (!specifier.startsWith('workspace:') || closure.has(name)) continue - const depDir = dirsByName.get(name) - if (!depDir) throw new Error(`workspace dependency ${name} not found`) + const closure = new Map() + const queue = workspaceDependencies(dir, dirsByName) + for (const [name, depDir] of queue) { + if (closure.has(name)) continue closure.set(name, depDir) - workspaceDependencyClosure(depDir, dirsByName, closure) + queue.push(...workspaceDependencies(depDir, dirsByName)) } return closure } From 0eb83279700adb64d129036545e41b75faf49334 Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 16 Sep 2026 21:43:55 +0530 Subject: [PATCH 6/6] fix(account): validate the pack smoke's JSON inputs at the boundary --- packages/account/scripts/smokePack.ts | 50 ++++++++++++++++++--------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/packages/account/scripts/smokePack.ts b/packages/account/scripts/smokePack.ts index f45ae64946d..7cf1790c8ba 100644 --- a/packages/account/scripts/smokePack.ts +++ b/packages/account/scripts/smokePack.ts @@ -20,19 +20,25 @@ import { import { tmpdir } from 'node:os' import { join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' +import { z } from 'zod' -interface Manifest { - readonly name: string - readonly version: string - readonly exports: Readonly> - readonly dependencies?: Readonly> - readonly peerDependencies?: Readonly> -} +const zSpecifiers = z.record(z.string(), z.string()) -interface PackResult { - readonly filename: string - readonly files: ReadonlyArray<{ readonly path: string }> -} +const zManifest = z.object({ + name: z.string(), + version: z.string(), + exports: zSpecifiers, + dependencies: zSpecifiers.optional(), + peerDependencies: zSpecifiers.optional() +}) + +const zPackResult = z.object({ + filename: z.string(), + files: z.array(z.object({ path: z.string() })) +}) + +type Manifest = z.infer +type PackResult = z.infer const packageDir = fileURLToPath(new URL('..', import.meta.url)) const workspaceRoot = resolve(packageDir, '..', '..') @@ -50,8 +56,16 @@ function run(command: string, args: string[], cwd: string): string { }) } +function parseJson(schema: z.ZodType, text: string, origin: string): T { + const result = schema.safeParse(JSON.parse(text)) + return result.success + ? result.data + : fail(`${origin}: ${result.error.message}`) +} + function readManifest(dir: string): Manifest { - return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) + const path = join(dir, 'package.json') + return parseJson(zManifest, readFileSync(path, 'utf8'), path) } function workspacePackageDirs(): Map { @@ -90,14 +104,18 @@ function workspaceDependencyClosure( } function pack(dir: string, destination: string): PackResult { - return JSON.parse( - run('pnpm', ['pack', '--json', '--pack-destination', destination], dir) + return parseJson( + zPackResult, + run('pnpm', ['pack', '--json', '--pack-destination', destination], dir), + `pnpm pack --json in ${dir}` ) } function packedManifest(tarball: string): Manifest { - return JSON.parse( - run('tar', ['-xzOf', tarball, 'package/package.json'], packageDir) + return parseJson( + zManifest, + run('tar', ['-xzOf', tarball, 'package/package.json'], packageDir), + `package/package.json in ${tarball}` ) }