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
25 changes: 25 additions & 0 deletions lexicons/gcp/src/op/activities/floci-gcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
flociGcpExistsCommand,
flociGcpHealthUrl,
flociGcpEndpoint,
FLOCI_GCP_EMULATOR,
} from "./floci-gcp";
import { endpointEnvVars } from "@intentius/chant/op";

describe("floci-gcp lifecycle commands (typed emulator, not shell)", () => {
test("run command uses defaults and maps the port", () => {
Expand All @@ -27,3 +29,26 @@ describe("floci-gcp lifecycle commands (typed emulator, not shell)", () => {
expect(flociGcpEndpoint(4588)).toBe("http://localhost:4588");
});
});

describe("floci-gcp emulator capability (#1431)", () => {
// The bug: `env` returned {}, so `chant emulator up --lexicon gcp` booted the
// emulator and left GCP_ENDPOINT_URL unset — pointing describeResources and
// observeResourcesDeep, which read that variable and nothing else, at real GCP.
test("injects the endpoint under the variable the READ path honours", () => {
expect(FLOCI_GCP_EMULATOR.env("http://localhost:4588")).toEqual({
GCP_ENDPOINT_URL: "http://localhost:4588",
});
});

test("injects whatever endpoint it is given, not a hardcoded port", () => {
expect(FLOCI_GCP_EMULATOR.env("http://localhost:4599")).toEqual({
GCP_ENDPOINT_URL: "http://localhost:4599",
});
});

// `endpointEnvVars` derives its list by probing `env`, so an empty `env` also
// meant core believed gcp had no endpoint variable at all.
test("core can now derive gcp's endpoint variable from the capability", () => {
expect(endpointEnvVars(FLOCI_GCP_EMULATOR)).toEqual(["GCP_ENDPOINT_URL"]);
});
});
27 changes: 21 additions & 6 deletions lexicons/gcp/src/op/activities/floci-gcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,31 @@ export const FLOCI_GCP_SPEC: EmulatorSpec = {
};

/**
* The gcp plugin's emulator capability (#1345).
* The gcp plugin's emulator capability (#1345, corrected in #1431).
*
* `env` is deliberately empty: `gcpApply` reaches the emulator through an
* explicit `endpoint` argument rather than an ambient variable, so there is no
* var to inject and claiming one would be worse than claiming none. The
* endpoint is still reported by `chant emulator up --json`.
* The apply and read paths reach the emulator differently, and the capability
* exists for the one that cannot be told where to look:
*
* - **apply** — `gcpApply` takes an explicit `endpoint` argument. Nothing to
* inject; the caller already holds it.
* - **read** — `describeResources` and `observeResourcesDeep` take it from
* `GCP_ENDPOINT_URL` and nothing else (`../../describe-resources.ts`,
* `../../deep-observe.ts`). A reader given no variable talks to real GCP.
*
* `env` was empty because when #1345 declared this capability the second bullet
* was not yet true: GCP was observed through Config Connector over kubectl, so
* there genuinely was no variable to inject. #1209 moved observation onto the
* applier's own direct-REST transport about two hours later, and nothing
* re-read this comment. The result was an emulator that booted, reported its
* endpoint, and left every `--live` read pointed at production.
*
* Injecting it makes `chant emulator up --lexicon gcp` mean the same thing for
* gcp that it already means for aws and azure: the estate's reads land on the
* emulator you just started.
*/
export const FLOCI_GCP_EMULATOR: EmulatorCapability = {
spec: FLOCI_GCP_SPEC,
env: () => ({}),
env: (endpoint) => ({ GCP_ENDPOINT_URL: endpoint }),
};

const gcp = emulatorLifecycle(FLOCI_GCP_SPEC);
Expand Down