Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/src/mdi-native-archive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Relative to the CLI module in either packages/cli/src or packages/cli/dist.
export const BUNDLED_MDI_NATIVE_ARCHIVE_PATH = "../../../runtime-overlays/mdi-native/markdown-database-integration-4cf0a57.zip"
3 changes: 2 additions & 1 deletion packages/cli/src/recipe-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { compileSourcePackage, composerManagedHostCommandConfig, composerManaged
import type { MountSpec, WorkspaceRecipe, WorkspaceRecipeDependencyOverlay, WorkspaceRecipeExtraPlugin, WorkspaceRecipeExtraTheme, WorkspaceRecipeRuntimeOverlay, WorkspaceRecipeStagedFile, WorkspaceRecipeWorkspace, WorkspaceRecipeWorkspacePreload, WorkspaceRecipeWorkspacePreloadRepository } from "@automattic/wp-codebox-core"
import { executeManagedHostCommand, resolvePluginEntrypointContract, resolveThemeEntrypointContract } from "@automattic/wp-codebox-core"
import { collectPreparedSourceCleanupPaths, DEFAULT_PREPARED_SOURCE_EXCLUDE_NAMES, localPreparedSourceProvenance, prepareLocalSourceStageSync, SANDBOX_WORKSPACE_ROOT, type PreparedSourceProvenance } from "@automattic/wp-codebox-core/internals"
import { BUNDLED_MDI_NATIVE_ARCHIVE_PATH } from "./mdi-native-archive.js"
import { registerRuntimeOverlayDescriptor, runtimeOverlayDescriptor } from "./runtime-overlay-registry.js"
import { evaluateSourcePolicy, evaluateZipSourcePolicy, sourcePolicySnapshot, type SourcePolicyIssue } from "./source-policy.js"
import { prepareLocalZipSource, prepareZipSource } from "./zip-source.js"
Expand All @@ -20,7 +21,7 @@ const MAX_COMPOSER_INSTALLER_PATHS = 64
const MAX_COMPOSER_INSTALLER_PACKAGES = 256
const MAX_COMPOSER_PACKAGE_TREE_ENTRIES = 100_000
const BUNDLED_MDI_NATIVE_SOURCE = "wp-codebox:mdi-native"
const BUNDLED_MDI_NATIVE_ARCHIVE = fileURLToPath(new URL("../../../runtime-overlays/mdi-native/markdown-database-integration-4cf0a57.zip", import.meta.url))
const BUNDLED_MDI_NATIVE_ARCHIVE = fileURLToPath(new URL(BUNDLED_MDI_NATIVE_ARCHIVE_PATH, import.meta.url))

export interface PreparedWorkspaceMount {
source: string
Expand Down
19 changes: 17 additions & 2 deletions scripts/package-release-artifact.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { execFile } from "node:child_process"
import { createHash } from "node:crypto"
import { chmod, cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
import { chmod, cp, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
import { arch, platform } from "node:os"
import { tmpdir } from "node:os"
import { createRequire } from "node:module"
import { dirname, join, relative, resolve, sep } from "node:path"
import { promisify } from "node:util"

import { BUNDLED_MDI_NATIVE_ARCHIVE_PATH } from "../packages/cli/src/mdi-native-archive.ts"
import { materializeSharpReleaseRuntime, sharpRuntimePackageNames } from "./lib/materialize-sharp-release-runtime.ts"
import { normalizeReleasePlatform } from "./lib/release-target.ts"

Expand Down Expand Up @@ -89,6 +90,8 @@ exec "\${NODE_BIN}" "\${SCRIPT_DIR}/../packages/cli/dist/index.js" "$@"
// the public entrypoint contract again at the final archive boundary.
await chmod(join(packageRoot, "packages", "cli", "dist", "index.js"), 0o755)

await assertBundledMdiNativeArchive(packageRoot)

await rm(releaseRoot, recursiveRmOptions)
await mkdir(releaseRoot, { recursive: true })
await cp(packageRoot, join(releaseRoot, "wp-codebox-cli"), { recursive: true })
Expand Down Expand Up @@ -139,8 +142,20 @@ async function materializePinnedPhpWasmOverlay(root: string): Promise<void> {
filter: (path) => relative(source, path).split(sep)[0] !== "node_modules",
})
await cp(join(root, "runtime-overlays", provenance), join(root, output))
await rm(source, recursiveRmOptions)
}
}

async function assertBundledMdiNativeArchive(root: string): Promise<void> {
const archivePath = resolve(root, "packages", "cli", "dist", BUNDLED_MDI_NATIVE_ARCHIVE_PATH)
const archive = await lstat(archivePath)
if (!archive.isFile() || archive.size === 0) {
throw new Error(`Expected a nonempty bundled MDI native archive at ${archivePath}`)
}
const provenancePath = join(dirname(archivePath), "provenance.json")
if (!(await lstat(provenancePath)).isFile()) {
throw new Error(`Missing bundled MDI native provenance at ${provenancePath}`)
}
await rm(join(root, "runtime-overlays"), recursiveRmOptions)
}

async function materializeWorkspacePackages(root: string): Promise<void> {
Expand Down
9 changes: 8 additions & 1 deletion tests/release-package-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { execFile } from "node:child_process"
import { cp, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises"
import { createHash } from "node:crypto"
import { tmpdir } from "node:os"
import { join, relative, resolve } from "node:path"
import { dirname, join, relative, resolve } from "node:path"
import { pathToFileURL } from "node:url"
import { promisify } from "node:util"

import { BUNDLED_MDI_NATIVE_ARCHIVE_PATH } from "../packages/cli/src/mdi-native-archive.ts"
import { normalizeReleasePlatform, releaseTargetMatchesHost } from "../scripts/lib/release-target.ts"
import { sharpRuntimePackageNames } from "../scripts/lib/materialize-sharp-release-runtime.ts"

Expand Down Expand Up @@ -109,6 +110,12 @@ try {
const pluginCliRoot = join(pluginExtraction, "wp-codebox", "vendor", "wp-codebox-cli")
const tarCliRoot = join(cliExtraction, "wp-codebox-cli")
for (const root of [pluginCliRoot, tarCliRoot]) {
const mdiArchive = resolve(root, "packages", "cli", "dist", BUNDLED_MDI_NATIVE_ARCHIVE_PATH)
const mdiProvenance = JSON.parse(await readFile(join(dirname(mdiArchive), "provenance.json"), "utf8"))
assert.equal(createHash("sha256").update(await readFile(mdiArchive)).digest("hex"), mdiProvenance.sha256, "packaged MDI archive must match its provenance")
for (const version of ["8-3", "8-4"]) {
await assert.rejects(lstat(join(root, "runtime-overlays", `php-wasm-node-${version}`)), { code: "ENOENT" }, "packaged CLI must not duplicate relocated PHP-WASM overlays")
}
const cliBuildProvenance = JSON.parse(await readFile(join(root, "packages", "cli", "dist", "cli-build-provenance.json"), "utf8"))
assert.equal(cliBuildProvenance.schema, "wp-codebox/cli-build-provenance/v1")
assert.equal(cliBuildProvenance.package.version, JSON.parse(await readFile(join(root, "packages", "cli", "package.json"), "utf8")).version)
Expand Down
22 changes: 11 additions & 11 deletions tests/runtime-services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { spawnSync } from "node:child_process"
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
import { createServer } from "node:net"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { join, resolve } from "node:path"
import { runRecipeBuildCommand } from "../packages/cli/src/commands/recipe-build.ts"
import { executeRuntimeServiceProcess, linuxProcessGroupHasLiveMembers, parseLoopbackPort, provisionRuntimeServices, provisionRuntimeServicesForRecipe, RuntimeServiceProvisionError, runtimeServiceEvidenceFromError, runtimeServicePlan, waitForMysqlProtocol, type RuntimeServiceDependencies } from "../packages/cli/src/runtime-services.ts"
import { planWorkspaceRecipe } from "../packages/cli/src/recipe-dry-run.ts"
import { cleanupRecipePreparedSources, prepareRecipeExtraPlugins } from "../packages/cli/src/recipe-sources.ts"
import { cleanupRecipePreparedSources, prepareRecipeExtraPlugins, recipeSource } from "../packages/cli/src/recipe-sources.ts"
import { executeSmtpSinkRecipeOperation } from "../packages/cli/src/smtp-sink-recipe-operations.ts"
import { recipePolicy, validateWorkspaceRecipeSemantics } from "../packages/cli/src/recipe-validation.ts"
import { buildWordPressPhpunitRecipe } from "../packages/runtime-core/src/recipe-builders.ts"
Expand Down Expand Up @@ -78,24 +78,24 @@ assert.throws(
const sqlitePhpunitRecipe = buildWordPressPhpunitRecipe({ pluginSlug: "example" })
assert.equal(sqlitePhpunitRecipe.inputs?.services, undefined)
assert.equal(sqlitePhpunitRecipe.workflow.steps[0].args?.some((arg) => arg.startsWith("database-type=")), false)
assert.deepEqual(JSON.parse(await readFile("runtime-overlays/mdi-native/provenance.json", "utf8")), {
schema: "wp-codebox/mdi-native-overlay-provenance/v1",
repository: "Automattic/markdown-database-integration",
revision: "4cf0a57f68e002f665d3ac195cd86c89dd748e05",
archive: "markdown-database-integration-4cf0a57.zip",
sha256: "f359e454849341fc929be308220254c603cf15d2650c1a9e7037372b5de59ac4",
})
const mdiProvenance = JSON.parse(await readFile("runtime-overlays/mdi-native/provenance.json", "utf8"))
assert.equal(mdiProvenance.schema, "wp-codebox/mdi-native-overlay-provenance/v1")
assert.equal(mdiProvenance.repository, "Automattic/markdown-database-integration")
assert.match(mdiProvenance.revision, /^[a-f0-9]{40}$/)
assert.match(mdiProvenance.sha256, /^[a-f0-9]{64}$/)
assert.equal(mdiProvenance.archive, `markdown-database-integration-${mdiProvenance.revision.slice(0, 7)}.zip`)
assert.equal(recipeSource("wp-codebox:mdi-native").resolvedUrl, resolve("runtime-overlays/mdi-native", mdiProvenance.archive))
const mdiPhpunitRecipe = buildWordPressPhpunitRecipe({ pluginSlug: "example", databaseType: "mdi-native" })
assert.equal(mdiPhpunitRecipe.runtime?.databaseSetup, "custom-drop-in")
assert.equal(mdiPhpunitRecipe.inputs?.services, undefined)
assert.ok(mdiPhpunitRecipe.workflow.steps[0].args?.includes("database-type=mdi-native"))
assert.deepEqual(mdiPhpunitRecipe.inputs?.extra_plugins?.at(-1), {
source: "wp-codebox:mdi-native",
sha256: "f359e454849341fc929be308220254c603cf15d2650c1a9e7037372b5de59ac4",
sha256: mdiProvenance.sha256,
slug: "markdown-database-integration",
pluginFile: "markdown-database-integration/markdown-database-integration.php",
activate: false,
metadata: { phase: "pre-install", databaseDropIn: true, revision: "4cf0a57f68e002f665d3ac195cd86c89dd748e05" },
metadata: { phase: "pre-install", databaseDropIn: true, revision: mdiProvenance.revision },
})
const preparedMdiPlugins = await prepareRecipeExtraPlugins(mdiPhpunitRecipe, process.cwd())
try {
Expand Down
Loading