Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import { renderTerraformPlan } from "../../../open-sse/services/compression/engines/rtk/renderers/terraformPlan.ts";

const det = {
  type: "terraform-plan",
  command: "terraform plan",
  confidence: 1,
  category: "infra",
  matchedPatterns: [],
};

test("summarizes plan into +N ~M -K plus resources", () => {
  const input = `Terraform will perform the following actions:
  # aws_instance.web will be created
  + resource "aws_instance" "web" { ... many lines ... }
  # aws_s3_bucket.data will be updated in-place
  ~ resource "aws_s3_bucket" "data" { ... }
Plan: 1 to add, 1 to change, 0 to destroy.`;
  const r = renderTerraformPlan(input, det);
  assert.equal(r.changed, true);
  assert.ok(r.text.includes("Plan: +1 ~1 -0"));
  assert.ok(r.text.includes("aws_instance.web"));
  assert.ok(!r.text.includes('resource "aws_instance" "web" {'));
  // Regression (core review): the verb must not be duplicated ("will be will be created").
  assert.ok(!r.text.includes("will be will be"));
  assert.ok(r.text.includes("# aws_instance.web will be created"));
  assert.ok(r.text.includes("# aws_s3_bucket.data will be updated in-place"));
});

test("no-changes ⇒ no-op", () => {
  const r = renderTerraformPlan(
    "No changes. Your infrastructure matches the configuration.",
    det,
  );
  assert.equal(r.changed, false);
});