chat-ui-agent-demo / src /lib /server /databasePackaging.spec.ts
Mike0021's picture
deploy: production agent journey fixes (part 2)
77374bd verified
Raw History Blame Contribute Delete
2.34 kB
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
describe("embedded MongoDB packaging", () => {
it("keeps mongodb-memory-server as a runtime dependency", async () => {
const packageJson = JSON.parse(
await readFile(new URL("../../../package.json", import.meta.url), "utf8")
) as {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
};
// adapter-node externalizes runtime dependencies but bundles dev dependencies.
// Bundling this CommonJS package into an ESM chunk drops its __dirname and
// crashes the no-MONGODB_URL fallback before the app can start.
expect(packageJson.dependencies?.["mongodb-memory-server"]).toBe("^10.1.2");
expect(packageJson.devDependencies?.["mongodb-memory-server"]).toBeUndefined();
});
it("runs the trap-bearing entrypoint shell as PID 1", async () => {
const [dockerfile, entrypoint] = await Promise.all([
readFile(new URL("../../../Dockerfile", import.meta.url), "utf8"),
readFile(new URL("../../../entrypoint.sh", import.meta.url), "utf8"),
]);
// A `bash -c` wrapper receives the container SIGTERM instead of the shell whose
// traps flush the final MongoDB snapshot during a Space restart.
expect(dockerfile).toContain('CMD ["/bin/bash", "/app/entrypoint.sh"]');
expect(dockerfile).not.toContain('CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]');
expect(dockerfile).not.toContain("npm install -g dotenv-cli");
expect(entrypoint).toContain("--env-file-if-exists=/app/.env");
expect(entrypoint).not.toMatch(/\bdotenv\s+-e\b/u);
});
it("packages the MongoDB handoff gate at the entrypoint default path", async () => {
const [dockerfile, entrypoint] = await Promise.all([
readFile(new URL("../../../Dockerfile", import.meta.url), "utf8"),
readFile(new URL("../../../entrypoint.sh", import.meta.url), "utf8"),
]);
expect(dockerfile).toContain(
"COPY --chown=1000 mongo-handoff-gate.mjs /app/mongo-handoff-gate.mjs"
);
expect(entrypoint).toContain("MONGO_HANDOFF_GATE_EXECUTABLE");
expect(entrypoint).toContain("MONGO_HANDOFF_GATE_SCRIPT");
expect(entrypoint).toContain("/app/mongo-handoff-gate.mjs");
expect(entrypoint).not.toContain("MONGO_HANDOFF_GATE_COMMAND");
expect(entrypoint).not.toMatch(/bash\s+-c\s+[^\n]*mongo_handoff_gate/u);
});
});