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
32 changes: 32 additions & 0 deletions packages/cli/src/commands/lambda/sam.test.ts
Original file line number Diff line number Diff line change
@@ -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/);
});
});
9 changes: 4 additions & 5 deletions packages/cli/src/commands/lambda/sam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading