Skip to content

Commit 6652e74

Browse files
committed
test: keep coded stderr in compiler goldens when --json prints an error document
plan --json now prints {"error": ...} on stdout when it fails. The golden builder read that document as a report with no diagnostics; it now records the coded stderr for it, so the goldens keep checking the error.
1 parent 48e67e5 commit 6652e74

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎scripts/compiler_differential/_helpers/goldens/goldens.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
GOLDEN_SUFFIX,
3333
GOLDEN_VERSION_MASK,
3434
GOLDEN_WORK_MASK,
35+
MACHINE_ERROR_KEY,
3536
PROJECT_DIRECTORY,
3637
)
3738
from scripts.compiler_differential.models import (
@@ -155,7 +156,7 @@ def _command(
155156
"exit_code": "timed out" if outcome.timed_out else outcome.exit_code,
156157
"diagnostics": (
157158
report.get("diagnostics", [])
158-
if report is not None
159+
if report is not None and MACHINE_ERROR_KEY not in report
159160
else _lines(
160161
text=normalize_stderr(_masked(text=outcome.stderr, masked_paths=masked_paths))
161162
)

‎scripts/compiler_differential/constants.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
GOLDEN_LABEL: str = "golden"
2424
GOLDEN_FULL_REPORT_LABEL_PREFIX: str = "refactor-"
2525
GOLDEN_REPORT_KEY: str = "report"
26+
MACHINE_ERROR_KEY: str = "error"
2627
GOLDEN_MANIFEST_DROPPED_KEYS: frozenset[str] = frozenset({"metadata", "child_map"})
2728
GOLDEN_MANIFEST_RESOURCE_SECTIONS: tuple[str, ...] = ("nodes", "sources", "macros")
2829
GOLDEN_RESOURCE_DROPPED_FIELDS: frozenset[str] = frozenset(

‎tests/unit/scripts/compiler_differential/_helpers/goldens/helpers.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ def project_run(*, message: str, compiled_sql: str) -> ProjectRun:
4242
}
4343
),
4444
)
45+
46+
47+
def machine_error_run() -> ProjectRun:
48+
"""A `plan --json` run that failed with the machine error document and a coded stderr."""
49+
50+
error: dict[str, object] = {"error": {"code": "C214", "message": "no manifest", "help": None}}
51+
return ProjectRun(
52+
outcomes=(
53+
CommandOutcome(
54+
label="plan",
55+
exit_code=1,
56+
stdout=json.dumps(error),
57+
stderr="error[C214]: no manifest\n",
58+
),
59+
),
60+
compiled={},
61+
manifest=None,
62+
)

‎tests/unit/scripts/compiler_differential/_helpers/goldens/test_compiler_goldens.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from tests.unit.scripts.compiler_differential._helpers.goldens.helpers import (
2222
PROJECT_PATH,
23+
machine_error_run,
2324
project_run,
2425
)
2526

@@ -98,7 +99,23 @@ def test_given_corpus_project_when_locating_its_golden_then_only_golden_corpora_
9899
"parent_map": {"model.orders.customer_totals": []},
99100
},
100101
},
101-
)
102+
),
103+
GoldenPayloadTestCase(
104+
description="machine_error_document_keeps_the_coded_stderr",
105+
run=machine_error_run(),
106+
masked_paths=(),
107+
expected_payload={
108+
"commands": [
109+
{
110+
"label": "plan",
111+
"exit_code": 1,
112+
"diagnostics": ["error[C214]: no manifest", ""],
113+
}
114+
],
115+
"compiled": {},
116+
"manifest": None,
117+
},
118+
),
102119
],
103120
ids=lambda case: case.description,
104121
)

0 commit comments

Comments
 (0)