feat(aws): setup script editor
Build App (Preview) / compute-version (pull_request) Successful in 6s
Secret Scan / scan (push) Successful in 7s
Secret Scan / scan (pull_request) Successful in 14s
Build App (Preview) / create-release (pull_request) Successful in 6s
Build App (Preview) / build-macos (pull_request) Successful in 6m3s
Build App (Preview) / test (pull_request) Successful in 8m39s
Build App (Preview) / build-windows (pull_request) Successful in 11m38s
Build Container / build-container (pull_request) Successful in 17m24s
Build App (Preview) / build-linux (pull_request) Failing after 21m19s
Build App (Preview) / prune-previews (pull_request) Skipped
Build App (Preview) / compute-version (pull_request) Successful in 6s
Secret Scan / scan (push) Successful in 7s
Secret Scan / scan (pull_request) Successful in 14s
Build App (Preview) / create-release (pull_request) Successful in 6s
Build App (Preview) / build-macos (pull_request) Successful in 6m3s
Build App (Preview) / test (pull_request) Successful in 8m39s
Build App (Preview) / build-windows (pull_request) Successful in 11m38s
Build Container / build-container (pull_request) Successful in 17m24s
Build App (Preview) / build-linux (pull_request) Failing after 21m19s
Build App (Preview) / prune-previews (pull_request) Skipped
HostSection gets a monospace "Setup script" textarea (saved on blur, blank as none) with the 32 KiB UTF-8 limit checked using the backend's message, and notes on when it runs (as claude, bash -e, after the clone, every start, 30 minutes, output in the Overview card) and what it gets under copy-at-connect. Also in Host settings: the environment's advisory lifetime cap (Q8), read by a new aws_environment_max_hours command, and the copy-at-connect limits (no CA before the first connect, removed credentials linger in a running task, no setup re-run after a re-clone), documented in CLAUDE.md too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5388db487e
commit
9e1e72d2a4
13 files changed
+274
-10
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { cleanup, render, screen, fireEvent, waitFor, within } from "@testing-library/react";
|
||||
import { act, cleanup, render, screen, fireEvent, waitFor, within } from "@testing-library/react";
|
||||
import RuntimeSection from "./RuntimeSection";
|
||||
import AccessSection from "./AccessSection";
|
||||
import WorkspaceSection from "./WorkspaceSection";
|
||||
@@ -12,6 +12,7 @@ import { useAppState } from "../../../../store/appState";
|
||||
const OFF_BRIDGE: AuthBridgeStatus = { enabled: false, active_ports: [], conflicts: [] };
|
||||
const removeAwsResources = vi.fn();
|
||||
const awsCostEstimate = vi.fn(async (..._args: unknown[]) => null as unknown);
|
||||
const awsEnvironmentMaxHours = vi.fn(async (_id: string) => 0 as number | null);
|
||||
|
||||
vi.mock("../../../../lib/tauri-commands", () => ({
|
||||
getAuthBridgeStatus: vi.fn(async () => OFF_BRIDGE),
|
||||
@@ -19,6 +20,7 @@ vi.mock("../../../../lib/tauri-commands", () => ({
|
||||
inspectCaCertPath: vi.fn(async () => null),
|
||||
removeAwsResources: (id: string, discard: boolean) => removeAwsResources(id, discard),
|
||||
awsCostEstimate: (...args: unknown[]) => awsCostEstimate(...args),
|
||||
awsEnvironmentMaxHours: (id: string) => awsEnvironmentMaxHours(id),
|
||||
}));
|
||||
vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => {}) }));
|
||||
vi.mock("@tauri-apps/plugin-dialog", () => ({ open: vi.fn(async () => null) }));
|
||||
@@ -323,7 +325,12 @@ describe("HostSection", () => {
|
||||
p.aws = { ...p.aws!, secrets_delivery: "copy_at_connect", gateway_sidecar: false };
|
||||
renderHost(p);
|
||||
const note = screen.getByRole("note", { name: "Copied when you connect" });
|
||||
expect(note).toHaveTextContent("Private repositories clone after you connect.");
|
||||
expect(note).toHaveTextContent(
|
||||
"Private repositories clone, and the setup script runs, after you connect (or after 5 minutes without).",
|
||||
);
|
||||
expect(note).toHaveTextContent(/Claude Code's self-update may fail until then/);
|
||||
expect(note).toHaveTextContent("SSH keys, a Git token or variables you remove from the project stay in a running workspace until it stops.");
|
||||
expect(note).toHaveTextContent(/not run again when a later connect re-clones/);
|
||||
expect(note).toHaveTextContent(
|
||||
"Scheduled jobs and the setup script never get the API keys or custom variables; Git and SSH work once the app has connected.",
|
||||
);
|
||||
@@ -345,6 +352,76 @@ describe("HostSection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("saves the setup script on blur, and a blank one as none", async () => {
|
||||
renderHost();
|
||||
const box = screen.getByLabelText("Setup script");
|
||||
expect(box.tagName).toBe("TEXTAREA");
|
||||
expect(box.className).toContain("font-mono");
|
||||
expect(box.className).not.toContain("focus:outline-none");
|
||||
fireEvent.change(box, { target: { value: "sudo apt-get install -y jq\n" } });
|
||||
expect(screen.getByText(/27 of 32,768 bytes/)).toBeInTheDocument();
|
||||
fireEvent.blur(box);
|
||||
await waitFor(() => expect(save).toHaveBeenCalledTimes(1));
|
||||
expect(save.mock.calls[0][0].aws.setup_script).toBe("sudo apt-get install -y jq\n");
|
||||
cleanup();
|
||||
|
||||
const p = awsProject();
|
||||
p.aws = { ...p.aws!, setup_script: "echo hi" };
|
||||
renderHost(p);
|
||||
const again = screen.getByLabelText("Setup script");
|
||||
expect(again).toHaveValue("echo hi");
|
||||
fireEvent.change(again, { target: { value: " \n" } });
|
||||
fireEvent.blur(again);
|
||||
await waitFor(() => expect(save).toHaveBeenCalledTimes(2));
|
||||
expect(save.mock.calls[1][0].aws.setup_script).toBeNull();
|
||||
});
|
||||
|
||||
it("refuses a setup script over 32 KiB with the backend's message", () => {
|
||||
renderHost();
|
||||
const box = screen.getByLabelText("Setup script");
|
||||
// 16,385 two-byte characters: 32,770 UTF-8 bytes.
|
||||
fireEvent.change(box, { target: { value: "é".repeat(16_385) } });
|
||||
fireEvent.blur(box);
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("The setup script is 32770 bytes; the limit is 32768");
|
||||
expect(box).toHaveAttribute("aria-invalid", "true");
|
||||
expect(save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("says when and how the setup script runs", () => {
|
||||
renderHost();
|
||||
expect(screen.getByText(/Runs on every start, as claude, with bash -e/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/once the repositories are cloned/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/stopped after 30 minutes, and its output shows in the Overview/)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/never gets the API keys or custom variables/)).toBeNull();
|
||||
cleanup();
|
||||
|
||||
const p = awsProject();
|
||||
p.aws = { ...p.aws!, secrets_delivery: "copy_at_connect" };
|
||||
renderHost(p);
|
||||
expect(
|
||||
screen.getByText(/the setup script waits for the app's first connect \(at most 5 minutes\) and never gets the API keys or custom variables/),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the environment's lifetime cap when it has one", async () => {
|
||||
awsEnvironmentMaxHours.mockResolvedValueOnce(24);
|
||||
renderHost();
|
||||
expect(
|
||||
await screen.findByText("This environment stops workspaces after 24 h (advisory)."),
|
||||
).toBeInTheDocument();
|
||||
expect(awsEnvironmentMaxHours).toHaveBeenCalledWith(awsProject().id);
|
||||
cleanup();
|
||||
|
||||
for (const none of [0, null]) {
|
||||
awsEnvironmentMaxHours.mockResolvedValueOnce(none);
|
||||
renderHost();
|
||||
await waitFor(() => expect(awsEnvironmentMaxHours).toHaveBeenCalled());
|
||||
await act(async () => {});
|
||||
expect(screen.queryByText(/stops workspaces after/)).toBeNull();
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not let the credentials setting change while the workspace runs", () => {
|
||||
renderHost(awsProject(), true);
|
||||
expect(screen.getByRole("radio", { name: "Copied when you connect" })).toBeDisabled();
|
||||
|
||||
@@ -9,6 +9,10 @@ import {
|
||||
COPY_AT_CONNECT_SSH_NOTE,
|
||||
COPY_AT_CONNECT_WARNINGS,
|
||||
SECRETS_MANAGER_HINT,
|
||||
SETUP_SCRIPT_COPY_AT_CONNECT_NOTE,
|
||||
SETUP_SCRIPT_HINT,
|
||||
MAX_SETUP_SCRIPT_BYTES,
|
||||
setupScriptProblem,
|
||||
EFS_HINT,
|
||||
EPHEMERAL_WARNING,
|
||||
FARGATE_CPUS,
|
||||
@@ -25,7 +29,7 @@ import Button from "../../../ui/Button";
|
||||
import Modal from "../../../ui/Modal";
|
||||
import Toggle from "../../../ui/Toggle";
|
||||
import SegmentedControl from "../../../ui/SegmentedControl";
|
||||
import Field, { ConfigGroup, SwitchRow, inputClass, selectClass } from "../../../ui/Field";
|
||||
import Field, { ConfigGroup, SwitchRow, inputClass, monoInputClass, selectClass } from "../../../ui/Field";
|
||||
import RepoListEditor from "../../RepoListEditor";
|
||||
import AwsCostEstimate from "../AwsCostEstimate";
|
||||
|
||||
@@ -57,6 +61,10 @@ export default function HostSection({ project, save, disabled }: Props) {
|
||||
const [idle, setIdle] = useState(String(aws.idle_stop_minutes ?? DEFAULT_IDLE_MINUTES));
|
||||
const [idleProblem, setIdleProblem] = useState<string | null>(null);
|
||||
const [confirmRemoveResources, setConfirmRemoveResources] = useState(false);
|
||||
const [setupScript, setSetupScript] = useState(aws.setup_script ?? "");
|
||||
const [setupProblem, setSetupProblem] = useState<string | null>(null);
|
||||
// The environment's advisory lifetime cap (Q8), from its record.
|
||||
const [maxHours, setMaxHours] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setMemory(String(aws.memory_mib));
|
||||
@@ -64,6 +72,28 @@ export default function HostSection({ project, save, disabled }: Props) {
|
||||
setIdle(String(aws.idle_stop_minutes ?? DEFAULT_IDLE_MINUTES));
|
||||
}, [aws.memory_mib, aws.ephemeral_gib, aws.idle_stop_minutes]);
|
||||
|
||||
useEffect(() => {
|
||||
setSetupScript(aws.setup_script ?? "");
|
||||
}, [aws.setup_script]);
|
||||
|
||||
const region = project.aws_placement?.region;
|
||||
const environment = project.aws_placement?.environment;
|
||||
useEffect(() => {
|
||||
setMaxHours(null);
|
||||
if (!project.host_id || !environment) return;
|
||||
let cancelled = false;
|
||||
// Best effort: an unreadable record just shows no cap line.
|
||||
Promise.resolve()
|
||||
.then(() => commands.awsEnvironmentMaxHours(project.id))
|
||||
.then((h) => {
|
||||
if (!cancelled) setMaxHours(h ?? null);
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [project.id, project.host_id, region, environment]);
|
||||
|
||||
const saveAws = (patch: Partial<AwsWorkspaceConfig>) => save({ aws: { ...aws, ...patch } });
|
||||
|
||||
const hasResources = !!(
|
||||
@@ -97,6 +127,16 @@ export default function HostSection({ project, save, disabled }: Props) {
|
||||
if (ok && value !== aws.ephemeral_gib) void saveAws({ ephemeral_gib: value });
|
||||
};
|
||||
|
||||
const commitSetupScript = () => {
|
||||
const problem = setupScriptProblem(setupScript);
|
||||
setSetupProblem(problem);
|
||||
if (problem) return;
|
||||
const value = setupScript.trim() === "" ? null : setupScript;
|
||||
if (value !== (aws.setup_script ?? null)) void saveAws({ setup_script: value });
|
||||
};
|
||||
|
||||
const setupBytes = new TextEncoder().encode(setupScript).length;
|
||||
|
||||
const commitIdle = () => {
|
||||
const value = Number(idle);
|
||||
const ok = Number.isInteger(value) && value >= 5 && value <= 1440;
|
||||
@@ -125,6 +165,11 @@ export default function HostSection({ project, save, disabled }: Props) {
|
||||
{project.aws_placement?.environment}
|
||||
</dd>
|
||||
</dl>
|
||||
{maxHours !== null && maxHours > 0 && (
|
||||
<p className="text-xs text-[var(--text-secondary)]">
|
||||
This environment stops workspaces after {maxHours} h (advisory).
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Field label="CPU">
|
||||
@@ -413,6 +458,48 @@ export default function HostSection({ project, save, disabled }: Props) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="pt-2 border-t border-[var(--border-color)]">
|
||||
<Field
|
||||
label="Setup script"
|
||||
hint={
|
||||
<>
|
||||
{SETUP_SCRIPT_HINT}
|
||||
{aws.secrets_delivery === "copy_at_connect" && <> {SETUP_SCRIPT_COPY_AT_CONNECT_NOTE}</>}
|
||||
</>
|
||||
}
|
||||
>
|
||||
{(id) => (
|
||||
<>
|
||||
<textarea
|
||||
id={id}
|
||||
value={setupScript}
|
||||
disabled={disabled}
|
||||
rows={8}
|
||||
spellCheck={false}
|
||||
placeholder={"sudo apt-get update\nsudo apt-get install -y jq"}
|
||||
aria-invalid={setupProblem ? true : undefined}
|
||||
aria-describedby={`${id}-size`}
|
||||
onChange={(e) => setSetupScript(e.target.value)}
|
||||
onBlur={commitSetupScript}
|
||||
className={`${monoInputClass} min-h-[8rem] resize-y`}
|
||||
/>
|
||||
<p
|
||||
id={`${id}-size`}
|
||||
className={`mt-1 text-xs ${setupBytes > MAX_SETUP_SCRIPT_BYTES ? "text-[var(--error)]" : "text-[var(--text-secondary)]"}`}
|
||||
>
|
||||
{setupBytes.toLocaleString("en-US")} of {MAX_SETUP_SCRIPT_BYTES.toLocaleString("en-US")} bytes
|
||||
(32 KiB, UTF-8)
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</Field>
|
||||
{setupProblem && (
|
||||
<p role="alert" className="mt-1 text-xs text-[var(--error)]">
|
||||
{setupProblem}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="pt-2 border-t border-[var(--border-color)] flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
size="md"
|
||||
|
||||
@@ -146,9 +146,32 @@ export const EFS_HINT = "Everything in /workspace survives a stop; git and build
|
||||
export const COPY_AT_CONNECT_HINT =
|
||||
"API keys, the Git token, custom environment variables and the SSH and CA files are not stored in AWS: Triple-C copies them into the running workspace each time it connects.";
|
||||
export const COPY_AT_CONNECT_WARNINGS = [
|
||||
"Private repositories clone after you connect.",
|
||||
"Private repositories clone, and the setup script runs, after you connect (or after 5 minutes without).",
|
||||
"Scheduled jobs and the setup script never get the API keys or custom variables; Git and SSH work once the app has connected.",
|
||||
"Until the first connect the workspace has no corporate CA: behind a TLS-inspecting proxy, Claude Code's self-update may fail until then.",
|
||||
"SSH keys, a Git token or variables you remove from the project stay in a running workspace until it stops.",
|
||||
"The setup script is not run again when a later connect re-clones a repository that failed.",
|
||||
];
|
||||
/** Mirrors Rust `MAX_SETUP_SCRIPT_BYTES` (UTF-8 bytes). */
|
||||
export const MAX_SETUP_SCRIPT_BYTES = 32_768;
|
||||
|
||||
/** Why `script` can't be saved, or null. Mirrors (and words like) Rust
|
||||
* `validate_aws_workspace`'s setup-script checks. */
|
||||
export function setupScriptProblem(script: string): string | null {
|
||||
const bytes = new TextEncoder().encode(script).length;
|
||||
if (bytes > MAX_SETUP_SCRIPT_BYTES) {
|
||||
return `The setup script is ${bytes} bytes; the limit is ${MAX_SETUP_SCRIPT_BYTES}`;
|
||||
}
|
||||
if (script.includes("\0")) return "The setup script must not contain NUL characters";
|
||||
return null;
|
||||
}
|
||||
|
||||
/** What the setup script is, under its editor (phase 6 Q3). */
|
||||
export const SETUP_SCRIPT_HINT =
|
||||
"Runs on every start, as claude, with bash -e in /workspace once the repositories are cloned. It is stopped after 30 minutes, and its output shows in the Overview's start-up card. claude can use sudo (apt-get install …).";
|
||||
export const SETUP_SCRIPT_COPY_AT_CONNECT_NOTE =
|
||||
"With credentials copied when you connect, the setup script waits for the app's first connect (at most 5 minutes) and never gets the API keys or custom variables.";
|
||||
|
||||
/** Hybrid/EFS under copy-at-connect (ruling R6): ~/.ssh stays off EFS. */
|
||||
export const COPY_AT_CONNECT_SSH_NOTE =
|
||||
"~/.ssh is not kept on EFS: SSH keys copied in, or made in the workspace, are gone when it stops. Keys an earlier start left in /mnt/triple-c-home/.ssh stay there until you remove them.";
|
||||
|
||||
@@ -42,6 +42,10 @@ export const awsTaskLog = (projectId: string, limit: number) =>
|
||||
* idle workspace up). */
|
||||
export const awsWorkspaceStatus = (projectId: string) =>
|
||||
invoke<WorkspaceStatus | null>("aws_workspace_status", { projectId });
|
||||
/** The project's environment's advisory lifetime cap in hours (0 = none);
|
||||
* null when it can't be read. Never rejects for a missing project. */
|
||||
export const awsEnvironmentMaxHours = (projectId: string) =>
|
||||
invoke<number | null>("aws_environment_max_hours", { projectId });
|
||||
export const removeAwsResources = (projectId: string, discardData: boolean) =>
|
||||
invoke<Project>("remove_aws_resources", { projectId, discardData });
|
||||
export const rebuildProjectContainer = (projectId: string) =>
|
||||
|
||||
Reference in new issue
Block a user