Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.7 KB
Raw Blame
import { mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

// Mirrors PKG_PATH_ENV in scripts/release-naming.mjs, which cannot be imported
// here: its shebang breaks the Windows test runner. Divergence is self-
// reporting, not silent — the script would fall back to the real
// cli/package.json and every fixture-window assertion would fail.
const PKG_PATH_ENV = 'DIFYCTL_PKG_PATH'

// release-naming.mjs and release-r2-edge.mjs read their data from
// cli/package.json. Tests spawn them against this fixture instead, so
// assertions can name an exact version/channel without tracking the live release.

export const FIXTURE_VERSION = '7.7.7'
export const FIXTURE_CHANNEL = 'stable'
export const FIXTURE_TAG_PREFIX = 'difyctl-v'

export const FIXTURE_TARGET_IDS = [
  'linux-x64',
  'linux-arm64',
  'darwin-x64',
  'darwin-arm64',
  'windows-x64',
] as const

const FIXTURE_RELEASE = {
  tagPrefix: FIXTURE_TAG_PREFIX,
  binName: 'difyctl',
  checksumsSuffix: '-checksums.txt',
  targets: FIXTURE_TARGET_IDS.map((id) => ({
    id,
    bunTarget: `bun-${id}`,
    exe: id.startsWith('windows'),
  })),
}

export type PkgManifestOverrides = {
  version?: string
  channel?: string
}

// Returns the env additions that point a spawned script at the fixture.
export function pkgManifestEnv(overrides: PkgManifestOverrides = {}): Record<string, string> {
  const manifest = {
    version: overrides.version ?? FIXTURE_VERSION,
    difyctl: {
      channel: overrides.channel ?? FIXTURE_CHANNEL,
      release: FIXTURE_RELEASE,
    },
  }
  const path = join(mkdtempSync(join(tmpdir(), 'difyctl-pkg-')), 'package.json')
  writeFileSync(path, JSON.stringify(manifest))
  return { [PKG_PATH_ENV]: path }
}