Skip to content

Write HTML. Render video. Built for agents.

fix(cli): stop lambda deploy from pointing at a nonexistent --sam-template flag (#3879)

miga-heygena7e95c0e37c0
diff --git a/packages/cli/src/commands/lambda/sam.test.ts b/packages/cli/src/commands/lambda/sam.test.ts
new file mode 100644
index 0000000000..dc2744828c
--- /dev/null
+++ b/packages/cli/src/commands/lambda/sam.test.ts
@@ -0,0 +1,32 @@
+import { afterEach, describe, expect, it } from "vitest";
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { locateSamTemplate } from "./sam.js";
+
+let dir: string | undefined;
+
+afterEach(() => {
+ if (dir) rmSync(dir, { recursive: true, force: true });
+ dir = undefined;
+});
+
+describe("locateSamTemplate", () => {
+ it("returns the template path when it exists under repoRoot", () => {
+ dir = mkdtempSync(join(tmpdir(), "hf-lambda-sam-"));
+ const samDir = join(dir, "examples", "aws-lambda");
+ mkdirSync(samDir, { recursive: true });
+ const templatePath = join(samDir, "template.yaml");
+ writeFileSync(templatePath, "AWSTemplateFormatVersion: '2010-09-09'\n");
+
+ expect(locateSamTemplate(dir)).toBe(templatePath);
+ });
+
+ // No --sam-template flag exists; the error must not send users to one.
+ it("does not point users at the nonexistent --sam-template flag when the template is missing", () => {
+ dir = mkdtempSync(join(tmpdir(), "hf-lambda-sam-missing-"));
+
+ expect(() => locateSamTemplate(dir!)).toThrow(/HYPERFRAMES_REPO_ROOT/);
+ expect(() => locateSamTemplate(dir!)).not.toThrow(/--sam-template/);
+ });
+});
diff --git a/packages/cli/src/commands/lambda/sam.ts b/packages/cli/src/commands/lambda/sam.ts
index e2b2af5446..1f52ad4c69 100644
--- a/packages/cli/src/commands/lambda/sam.ts
+++ b/packages/cli/src/commands/lambda/sam.ts
@@ -60,17 +60,16 @@ export interface DeployOptions {
}
/**
- * Resolve the SAM template path relative to `repoRoot`. We look for the
- * `examples/aws-lambda/template.yaml` first (development checkout) and
- * fall back to the installed-package layout when running from a globally
- * installed `hyperframes` CLI.
+ * Resolve the SAM template path relative to `repoRoot`. No installed-package fallback: the
+ * template's `CodeUri` is relative to the monorepo, so it only works inside a checkout.
*/
export function locateSamTemplate(repoRoot: string): string {
const candidate = join(repoRoot, "examples", "aws-lambda", "template.yaml");
if (!existsSync(candidate)) {
throw new Error(
`[lambda] SAM template not found at ${candidate}. ` +
- `If you're running from an installed package, point --sam-template at your local copy of examples/aws-lambda/template.yaml.`,
+ "`hyperframes lambda deploy` needs a HyperFrames repo checkout: run it from one, " +
+ "or set HYPERFRAMES_REPO_ROOT to point at one.",
);
}
return candidate;