From caf7e90ca5bbbcf019e4731c65cfcb43b3a8d1d5 Mon Sep 17 00:00:00 2001 From: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Date: Tue, 25 Aug 2026 05:11:44 +0000 Subject: [PATCH] test(cli): tsconfig gap (#41224) --- cli/scripts/e2e-provision.ts | 5 ++- cli/scripts/release-naming.test.ts | 61 ++++++++++++++++------------- cli/scripts/release-r2-edge.test.ts | 9 ++--- cli/test/fixtures/pkg-manifest.ts | 11 ++++-- cli/tsconfig.json | 2 +- 5 files changed, 49 insertions(+), 39 deletions(-) diff --git a/cli/scripts/e2e-provision.ts b/cli/scripts/e2e-provision.ts index f6e980334d7..0ba1d5f5cdb 100644 --- a/cli/scripts/e2e-provision.ts +++ b/cli/scripts/e2e-provision.ts @@ -62,9 +62,10 @@ async function consoleLogin(): Promise<{ cookieString: string; csrfToken: string if (!res.ok) throw new Error(`console/api/login failed: HTTP ${res.status}`) const setCookies = res.headers.getSetCookie?.() ?? [] - const cookieString = setCookies.map((c) => c.split(';')[0]).join('; ') + const cookiePairs = setCookies.map((c) => c.split(';')[0] ?? '') + const cookieString = cookiePairs.join('; ') // cookie names may have __Host- prefix on HTTPS deployments - const csrfPair = setCookies.map((c) => c.split(';')[0]).find((p) => p.includes('csrf_token=')) + const csrfPair = cookiePairs.find((p) => p.includes('csrf_token=')) const csrfToken = csrfPair ? csrfPair.slice(csrfPair.indexOf('csrf_token=') + 'csrf_token='.length) : '' diff --git a/cli/scripts/release-naming.test.ts b/cli/scripts/release-naming.test.ts index 3494f54f1ef..306cf83f809 100644 --- a/cli/scripts/release-naming.test.ts +++ b/cli/scripts/release-naming.test.ts @@ -1,18 +1,24 @@ import { execFileSync } from 'node:child_process' import { fileURLToPath } from 'node:url' import { describe, expect, it } from 'vite-plus/test' -import { FIXTURE_COMPAT, pkgManifestEnv } from '../test/fixtures/pkg-manifest' +import { + FIXTURE_CHANNEL, + FIXTURE_COMPAT, + FIXTURE_TAG_PREFIX, + FIXTURE_VERSION, + FIXTURE_VERSION_CORE, + pkgManifestEnv, +} from '../test/fixtures/pkg-manifest' const SCRIPT = fileURLToPath(new URL('./release-naming.mjs', import.meta.url)) -function run( - args: string[], - env: Record = {}, -): { code: number; stdout: string; stderr: string } { +const PKG_ENV = pkgManifestEnv() + +function run(args: string[]): { code: number; stdout: string; stderr: string } { try { const stdout = execFileSync('node', [SCRIPT, ...args], { encoding: 'utf8', - env: { ...process.env, ...env }, + env: { ...process.env, ...PKG_ENV }, }) return { code: 0, stdout, stderr: '' } } catch (e) { @@ -23,9 +29,8 @@ function run( describe('release-naming compat-check', () => { const { minDify, maxDify } = FIXTURE_COMPAT // 2.0.0 .. 2.5.0 - const pkgEnv = pkgManifestEnv() const compatCheck = (difyVersion?: string) => - run(difyVersion === undefined ? ['compat-check'] : ['compat-check', difyVersion], pkgEnv).code + run(difyVersion === undefined ? ['compat-check'] : ['compat-check', difyVersion]).code it('accepts a version inside the window', () => { expect(compatCheck('2.3.0')).toBe(0) @@ -69,23 +74,22 @@ describe('release-naming compat-check', () => { }) describe('release-naming github-env', () => { - it('emits difyctlTag = tagPrefix + version', () => { - const { stdout } = run(['github-env']) - expect(stdout).toMatch(/^difyctlTag=difyctl-v0\.2\.0-alpha$/m) - }) - - it('still emits the existing trace fields', () => { - const { stdout } = run(['github-env']) - for (const key of ['version', 'channel', 'prerelease', 'minDify', 'maxDify', 'tagPrefix']) - expect(stdout).toMatch(new RegExp(`^${key}=`, 'm')) - }) - - // The only assertion against the live manifest: the window must exist and be - // well-formed, whatever release it currently points at. - it('emits a well-formed compat window from the real cli/package.json', () => { - const { stdout } = run(['github-env']) - expect(stdout).toMatch(/^minDify=\d+\.\d+\.\d+$/m) - expect(stdout).toMatch(/^maxDify=\d+\.\d+\.\d+$/m) + it('emits every manifest field for $GITHUB_ENV, plus a composed difyctlTag', () => { + const fields = Object.fromEntries( + run(['github-env']) + .stdout.split('\n') + .filter(Boolean) + .map((line) => [line.slice(0, line.indexOf('=')), line.slice(line.indexOf('=') + 1)]), + ) + expect(fields).toEqual({ + version: FIXTURE_VERSION, + channel: FIXTURE_CHANNEL, + prerelease: 'true', + minDify: FIXTURE_COMPAT.minDify, + maxDify: FIXTURE_COMPAT.maxDify, + tagPrefix: FIXTURE_TAG_PREFIX, + difyctlTag: `${FIXTURE_TAG_PREFIX}${FIXTURE_VERSION}`, + }) }) }) @@ -95,13 +99,14 @@ describe('release-naming edge channel', () => { }) it('edge-version derives -edge. from the package version', () => { - // package.json version is 0.2.0-alpha -> core 0.2.0 - expect(run(['edge-version', '2fd7b82']).stdout.trim()).toBe('0.2.0-edge.2fd7b82') + expect(run(['edge-version', '2fd7b82']).stdout.trim()).toBe( + `${FIXTURE_VERSION_CORE}-edge.2fd7b82`, + ) }) it('edge-version accepts a 40-char sha', () => { const sha = '2fd7b829e1f0aaaabbbbccccddddeeeeffff0000' - expect(run(['edge-version', sha]).stdout.trim()).toBe(`0.2.0-edge.${sha}`) + expect(run(['edge-version', sha]).stdout.trim()).toBe(`${FIXTURE_VERSION_CORE}-edge.${sha}`) }) it('edge-version rejects a non-hex sha', () => { diff --git a/cli/scripts/release-r2-edge.test.ts b/cli/scripts/release-r2-edge.test.ts index 0ddd6f36dd9..c4b981af008 100644 --- a/cli/scripts/release-r2-edge.test.ts +++ b/cli/scripts/release-r2-edge.test.ts @@ -4,7 +4,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { describe, expect, it } from 'vite-plus/test' -import { FIXTURE_COMPAT, pkgManifestEnv } from '../test/fixtures/pkg-manifest' +import { FIXTURE_COMPAT, FIXTURE_TARGET_IDS, pkgManifestEnv } from '../test/fixtures/pkg-manifest' const SCRIPT = fileURLToPath(new URL('./release-r2-edge.mjs', import.meta.url)) @@ -30,8 +30,7 @@ function run(args: string[]): { code: number; stdout: string; stderr: string } { function writeChecksums(version: string): string { const dir = mkdtempSync(join(tmpdir(), 'difyctl-manifest-')) - const ids = ['linux-x64', 'linux-arm64', 'darwin-x64', 'darwin-arm64', 'windows-x64'] - const lines = ids.map((id, i) => { + const lines = FIXTURE_TARGET_IDS.map((id, i) => { const exe = id === 'windows-x64' ? '.exe' : '' const sha = String(i).repeat(64) return `${sha} difyctl-v${version}-${id}${exe}` @@ -53,7 +52,7 @@ type ManifestJson = { buildDate: string compat: { minDify: string; maxDify: string } baseUrl: string - targets: Record + targets: Record<(typeof FIXTURE_TARGET_IDS)[number], { asset: string; sha256: string }> } type IndexBuild = { @@ -187,7 +186,7 @@ describe('release-r2-edge manifest', () => { function runIndex( currentContent: string | null, - build: Record, + build: Omit, existingDirs?: string[], ) { let currentArg = '-' diff --git a/cli/test/fixtures/pkg-manifest.ts b/cli/test/fixtures/pkg-manifest.ts index 92f2299ad35..7e65f1ae1bb 100644 --- a/cli/test/fixtures/pkg-manifest.ts +++ b/cli/test/fixtures/pkg-manifest.ts @@ -16,6 +16,11 @@ const PKG_PATH_ENV = 'DIFYCTL_PKG_PATH' // window" is a case distinct from either bound. export const FIXTURE_COMPAT = { minDify: '2.0.0', maxDify: '2.5.0' } +export const FIXTURE_VERSION_CORE = '7.7.7' +export const FIXTURE_VERSION = `${FIXTURE_VERSION_CORE}-alpha` +export const FIXTURE_CHANNEL = 'alpha' +export const FIXTURE_TAG_PREFIX = 'difyctl-v' + export const FIXTURE_TARGET_IDS = [ 'linux-x64', 'linux-arm64', @@ -25,7 +30,7 @@ export const FIXTURE_TARGET_IDS = [ ] as const const FIXTURE_RELEASE = { - tagPrefix: 'difyctl-v', + tagPrefix: FIXTURE_TAG_PREFIX, binName: 'difyctl', checksumsSuffix: '-checksums.txt', targets: FIXTURE_TARGET_IDS.map((id) => ({ @@ -44,9 +49,9 @@ export type PkgManifestOverrides = { // Returns the env additions that point a spawned script at the fixture. export function pkgManifestEnv(overrides: PkgManifestOverrides = {}): Record { const manifest = { - version: overrides.version ?? '0.2.0-alpha', + version: overrides.version ?? FIXTURE_VERSION, difyctl: { - channel: overrides.channel ?? 'alpha', + channel: overrides.channel ?? FIXTURE_CHANNEL, compat: overrides.compat ?? FIXTURE_COMPAT, release: FIXTURE_RELEASE, }, diff --git a/cli/tsconfig.json b/cli/tsconfig.json index 785042c96a7..939c74ae5d5 100644 --- a/cli/tsconfig.json +++ b/cli/tsconfig.json @@ -11,6 +11,6 @@ "outDir": "dist", "sourceMap": true }, - "include": ["src/**/*.ts", "test/**/*.ts"], // tests must be included for typechecking + "include": ["src/**/*.ts", "test/**/*.ts", "scripts/**/*.ts"], // tests must be included for typechecking "exclude": ["node_modules", "dist"] }