Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

test(deploy): cover Wrangler output separation

tianma-if7cfd0a413a02
diff --git a/.github/workflows/deploy-tools.yml b/.github/workflows/deploy-tools.yml
index 26294ab3..351edcaf 100644
--- a/.github/workflows/deploy-tools.yml
+++ b/.github/workflows/deploy-tools.yml
@@ -4,6 +4,7 @@ on:
pull_request:
paths:
- "scripts/cloudflare-deploy.mjs"
+ - "scripts/wrangler-output.mjs"
- "scripts/run-wrangler.mjs"
- "scripts/wrangler-runner.mjs"
- "scripts/verify-deployment.mjs"
@@ -20,6 +21,7 @@ on:
- main
paths:
- "scripts/cloudflare-deploy.mjs"
+ - "scripts/wrangler-output.mjs"
- "scripts/run-wrangler.mjs"
- "scripts/wrangler-runner.mjs"
- "scripts/verify-deployment.mjs"
diff --git a/tests/deployment-entrypoints.test.ts b/tests/deployment-entrypoints.test.ts
index 82149f8e..0580d30b 100644
--- a/tests/deployment-entrypoints.test.ts
+++ b/tests/deployment-entrypoints.test.ts
@@ -1,6 +1,14 @@
import { describe, expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
+import { spawnSync } from "node:child_process";
+import {
+ mkdirSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from "node:fs";
import { resolve } from "node:path";
+import { tmpdir } from "node:os";
const repositoryRoot = resolve(import.meta.dir, "..");
const readRepositoryFile = (path: string) => readFileSync(resolve(repositoryRoot, path), "utf8");
@@ -41,6 +49,112 @@ describe("Cloudflare deployment entrypoints", () => {
expect(chineseAgentDoc).toContain("自动查询 D1 UUID");
});
+ test("keeps D1 resolver diagnostics out of Wrangler JSON stdout", () => {
+ const workingDirectory = mkdtempSync(resolve(tmpdir(), "edgeever-wrangler-output-"));
+ const wranglerBinDirectory = resolve(
+ workingDirectory,
+ "node_modules",
+ "wrangler",
+ "bin",
+ );
+ const queryOutput = JSON.stringify([{ results: [{ name: "users" }] }]);
+ const inheritedEnvironment = Object.fromEntries(
+ ["PATH", "Path", "PATHEXT", "SystemRoot", "ComSpec", "TEMP", "TMP"]
+ .map((name) => [name, process.env[name]])
+ .filter((entry): entry is [string, string] => Boolean(entry[1])),
+ );
+ const environment = {
+ ...inheritedEnvironment,
+ EDGE_EVER_INSTANCE: "",
+ WRANGLER_CONFIG: resolve(workingDirectory, "wrangler.toml"),
+ };
+
+ try {
+ mkdirSync(wranglerBinDirectory, { recursive: true });
+ writeFileSync(
+ resolve(workingDirectory, "wrangler.toml"),
+ [
+ 'name = "edgeever"',
+ 'database_name = "edgeever"',
+ 'database_id = "00000000-0000-0000-0000-000000000000"',
+ 'bucket_name = "edgeever-resources"',
+ 'preview_bucket_name = "edgeever-resources-preview"',
+ 'migrations_dir = "migrations"',
+ "",
+ ].join("\n"),
+ );
+ writeFileSync(
+ resolve(wranglerBinDirectory, "wrangler.js"),
+ [
+ 'const args = process.argv.slice(2);',
+ 'if (args.includes("list")) {',
+ ' process.stdout.write(JSON.stringify([{ name: "edgeever", uuid: "11111111-1111-1111-1111-111111111111" }]));',
+ "} else {",
+ ` process.stdout.write(${JSON.stringify(`${queryOutput}\n`)});`,
+ "}",
+ "",
+ ].join("\n"),
+ );
+
+ const resultPath = resolve(workingDirectory, "result.json");
+ const runnerArguments = [
+ "d1",
+ "execute",
+ "DB",
+ "--remote",
+ "--command",
+ "SELECT name FROM sqlite_master",
+ "--json",
+ ];
+ const harness = spawnSync(
+ "node",
+ [
+ "-e",
+ [
+ 'const { spawnSync } = require("node:child_process");',
+ 'const { writeFileSync } = require("node:fs");',
+ "const result = spawnSync(",
+ " process.env.EDGE_TEST_RUNTIME,",
+ " [process.env.EDGE_TEST_RUNNER, ...JSON.parse(process.env.EDGE_TEST_ARGUMENTS)],",
+ ' { cwd: process.env.EDGE_TEST_CWD, encoding: "utf8", env: process.env },',
+ ");",
+ "writeFileSync(process.env.EDGE_TEST_RESULT, JSON.stringify({",
+ " status: result.status,",
+ " stdout: result.stdout,",
+ " stderr: result.stderr,",
+ " error: result.error?.message,",
+ "}));",
+ ].join("\n"),
+ ],
+ {
+ env: {
+ ...environment,
+ EDGE_TEST_ARGUMENTS: JSON.stringify(runnerArguments),
+ EDGE_TEST_CWD: workingDirectory,
+ EDGE_TEST_RESULT: resultPath,
+ EDGE_TEST_RUNNER: resolve(repositoryRoot, "scripts", "run-wrangler.mjs"),
+ EDGE_TEST_RUNTIME: process.execPath,
+ },
+ },
+ );
+ expect(harness.status).toBe(0);
+ const result = JSON.parse(readFileSync(resultPath, "utf8")) as {
+ error?: string;
+ status: number;
+ stderr: string;
+ stdout: string;
+ };
+
+ expect(result.error).toBeUndefined();
+ expect(result.status).toBe(0);
+ expect(result.stdout).toBe(`${queryOutput}\n`);
+ expect(result.stderr).toContain("[info] resolving Cloudflare D1 database id for edgeever");
+ expect(result.stderr).toContain("[ok] resolved D1 database edgeever");
+ } finally {
+ rmSync(workingDirectory, { force: true, recursive: true });
+ }
+ });
+
test("deployed repositories receive guarded daily upstream updates", () => {
const workflow = readRepositoryFile(".github/workflows/sync-edgeever-upstream.yml");
diff --git a/tests/wrangler-output.test.ts b/tests/wrangler-output.test.ts
deleted file mode 100644
index 8b9a376e..00000000
--- a/tests/wrangler-output.test.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { describe, expect, test } from "bun:test";
-import { writeWranglerNotice } from "../scripts/wrangler-output.mjs";
-
-describe("Wrangler wrapper output", () => {
- test("keeps diagnostics on stderr so stdout remains machine-readable", () => {
- let output = "";
- const stderr = {
- write: (chunk: string) => {
- output += chunk;
- return true;
- },
- };
-
- expect(writeWranglerNotice("info", "resolving D1 database", stderr)).toBe(true);
- expect(output).toBe("[info] resolving D1 database\n");
- });
-});