Files
oh-my-opencode/script/publish-workflow.test.ts
T

90 lines
4.0 KiB
TypeScript
Raw Normal View History

/// <reference types="bun-types" />
2026-04-04 01:51:48 +09:00
import { describe, expect, test } from "bun:test"
import { readFileSync } from "node:fs"
const ciWorkflowPath = new URL("../.github/workflows/ci.yml", import.meta.url)
2026-05-15 11:41:35 +09:00
const workflowChecks = [
{
path: ciWorkflowPath,
2026-05-15 11:41:35 +09:00
testRuns: [
2026-05-15 16:26:57 +09:00
"run: bun test",
2026-05-15 11:41:35 +09:00
"run: bun test src/shared/dist-bundle-bun-globals.test.ts",
],
},
{
path: new URL("../.github/workflows/publish.yml", import.meta.url),
2026-05-15 16:26:57 +09:00
testRuns: ["run: bun test"],
2026-05-15 11:41:35 +09:00
},
2026-04-04 01:51:48 +09:00
]
describe("test workflows", () => {
2026-04-06 18:45:33 +09:00
test("use pure bun test for workflows", () => {
2026-05-15 11:41:35 +09:00
for (const workflowCheck of workflowChecks) {
// #given
2026-05-15 11:41:35 +09:00
const workflow = readFileSync(workflowCheck.path, "utf8")
2026-04-04 01:51:48 +09:00
2026-05-15 11:41:35 +09:00
for (const testRun of workflowCheck.testRuns) {
expect(workflow).toContain(testRun)
}
2026-04-04 01:51:48 +09:00
}
})
test("exercise root checks across linux macos and windows", () => {
// #given
const workflow = readFileSync(ciWorkflowPath, "utf8")
// #when
const hasCrossOsMatrix = workflow.includes("os: [ubuntu-latest, macos-latest, windows-latest]")
const hasMatrixRunner = workflow.includes("runs-on: ${{ matrix.os }}")
// #then
expect(hasCrossOsMatrix, "CI root checks must cover Linux, macOS, and Windows").toBe(true)
expect(hasMatrixRunner, "CI root checks must run on the selected matrix OS").toBe(true)
})
test("runs codex compatibility checks on every supported os", () => {
// #given
const workflow = readFileSync(ciWorkflowPath, "utf8")
// #when
const hasCodexMatrixJob = workflow.includes("codex-compatibility:")
const hasCodexCommand = workflow.includes("run: bun run test:codex")
const buildNeedsCodexMatrix = workflow.includes("needs: [test, typecheck, codex-compatibility]")
// #then
expect(hasCodexMatrixJob, "CI must expose a Codex compatibility matrix job").toBe(true)
expect(hasCodexCommand, "Codex compatibility job must run the shared Codex test script").toBe(true)
expect(buildNeedsCodexMatrix, "Build must wait for Codex compatibility checks").toBe(true)
})
2026-05-29 12:18:42 +09:00
test("keeps LazyCodex deployment behind an explicit publish flag", () => {
// #given
const workflow = readFileSync(new URL("../.github/workflows/publish.yml", import.meta.url), "utf8")
// #when
const appliesCodexPluginVersion = workflow.includes("packages/omo-codex/plugin/.codex-plugin/plugin.json")
2026-05-29 12:18:42 +09:00
const flagDefaultsOff = workflow.includes("publish_lazycodex:") &&
workflow.includes('description: "Publish lazycodex npm alias and sync Codex marketplace"') &&
workflow.includes("default: false")
const syncsLazycodexMarketplace = workflow.includes("bun run script/sync-lazycodex-marketplace.ts")
const pushesLazycodexMarketplace = workflow.includes("code-yeongyu/lazycodex")
2026-05-29 12:18:42 +09:00
const gatesLazycodexNpmPublish = workflow.includes("name: Publish lazycodex") &&
workflow.includes("if: inputs.publish_lazycodex == true && steps.check-lazycodex.outputs.skip != 'true'")
const gatesLazycodexMarketplaceSync = workflow.includes("name: Sync LazyCodex Codex marketplace") &&
workflow.includes("if: inputs.publish_lazycodex == true")
const requiresLazycodexSyncToken = workflow.includes("secrets.LAZYCODEX_SYNC_TOKEN == ''") &&
workflow.includes("token: ${{ secrets.LAZYCODEX_SYNC_TOKEN }}")
// #then
expect(appliesCodexPluginVersion, "release must version the Codex plugin manifest before marketplace sync").toBe(true)
2026-05-29 12:18:42 +09:00
expect(flagDefaultsOff, "LazyCodex deployment must default to disabled").toBe(true)
expect(syncsLazycodexMarketplace, "release must sync the LazyCodex marketplace bundle").toBe(true)
expect(pushesLazycodexMarketplace, "release must target the LazyCodex repository").toBe(true)
2026-05-29 12:18:42 +09:00
expect(gatesLazycodexNpmPublish, "lazycodex npm publish must require publish_lazycodex=true").toBe(true)
expect(gatesLazycodexMarketplaceSync, "LazyCodex marketplace push must require publish_lazycodex=true").toBe(true)
expect(requiresLazycodexSyncToken, "release must require a cross-repo token for LazyCodex push").toBe(true)
})
2026-04-04 01:51:48 +09:00
})