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
34 changes: 29 additions & 5 deletions factory/scripts/inspect-inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ issue="$(mktemp "${TMPDIR:-/tmp}/factory-issue.XXXXXX")"
catalog="$(mktemp "${TMPDIR:-/tmp}/factory-catalog.XXXXXX")"

if ! jq -e -s '
def factory_comment:
.body as $body |
($body | contains("<!-- guide-factory-status -->")) or
(($body | startswith("## Scope check\n")) and
($body | contains("- **Outcome:** awaiting_scope")) and
($body | contains("Reply with the numbered decisions, then re-add `guide:draft`."))) or
(($body | startswith("## Guide factory failed\n")) and
((($body | contains("- **Outcome:** failed")) and
($body | contains("Resolve the findings, then re-add `guide:draft`."))) or
(($body | contains("**Workflow run:** https://github.com/")) and
($body | contains("Re-add `guide:draft` to retry after correcting the failure."))))) or
(($body | startswith("## Pipeline review\n")) and
($body | contains("- **Outcome:** ")) and
($body | contains("- **Provider:** ")) and
($body | contains("- **Run context:** ")) and
($body | contains("### Summary")) and
(($body | contains("Ready for review.")) or
($body | contains("Resolve the findings, then re-add `guide:draft`."))));
if length == 1 and (.[0] |
type == "object"
and (keys | sort) == (["comments","issue","repository","schema_version"] | sort)
Expand All @@ -38,11 +56,17 @@ if ! jq -e -s '
and ((.author | type) == "string" or (.author | type) == "null")
and (.created_at | type) == "string"
and (.body | type) == "string"))
then .[0] | {
schema_version, repository,
issue:{number:.issue.number,title:.issue.title,body:.issue.body,url:.issue.url,author:.issue.author},
comments:[.comments[] | {author,created_at,body}]
}
then .[0]
| (.comments | to_entries | map(select(.value | factory_comment)) | last | .key) as $latest_factory_comment
| {
schema_version, repository,
issue:{number:.issue.number,title:.issue.title,body:.issue.body,url:.issue.url,author:.issue.author},
comments:[
.comments | to_entries[]
| select((.value | factory_comment | not) or .key == $latest_factory_comment)
| .value | {author,created_at,body}
]
}
else error("invalid issue")
end
' "$issue_input" >"$issue" 2>/dev/null; then
Expand Down
4 changes: 2 additions & 2 deletions factory/scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ render_report_comment() {
else ("- " + ($values[$i]|bound)) end)] + [""] end;
([(if .outcome == "awaiting_scope" then "## Scope check"
elif .outcome == "failed" then "## Guide factory failed"
else "## Pipeline review" end), "",
else "## Pipeline review" end), "", "<!-- guide-factory-status -->", "",
"- **Outcome:** " + (.outcome|bound),
"- **Provider:** " + ((.provider // "unresolved")|bound),
"- **Slug:** " + ((.slug // "unresolved")|bound),
Expand Down Expand Up @@ -249,7 +249,7 @@ fail_run() {
register_temp "$body"
reason="$(jq -Rs -r '.[0:1000]' "$reason_file")"
run_url="https://github.com/$GH_REPO/actions/runs/${GITHUB_RUN_ID:-}"
printf '%s\n' '## Guide factory failed' '' "$reason" '' "**Workflow run:** $run_url" '' \
printf '%s\n' '## Guide factory failed' '' '<!-- guide-factory-status -->' '' "$reason" '' "**Workflow run:** $run_url" '' \
"Re-add \`guide:draft\` to retry after correcting the failure." >"$body"
remove_label guide:draft || status=$?
remove_label guide:in-progress || status=$?
Expand Down
24 changes: 24 additions & 0 deletions factory/tests/test-inspect-inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ if grep -Eq 'sensitive-tenant|sensitive\.example|streamable-http' "$TMP/out" "$T
fail 'input inspection leaked excluded catalog fields'
fi

jq '.comments = [
{author:"alice",created_at:"2026-08-28T00:00:00Z",body:"Operator evidence before retries."},
{author:"walker-tx",created_at:"2026-08-28T01:00:00Z",body:("## Guide factory failed\n\n" + ("OLD_FACTORY_HISTORY_CANARY" * 500) + "\n\n**Workflow run:** https://github.com/acme/docs/actions/runs/1\n\nRe-add `guide:draft` to retry after correcting the failure.")},
{author:"walker-tx",created_at:"2026-08-28T01:10:00Z",body:"## Scope check\n\n- **Outcome:** awaiting_scope\n\nReply with the numbered decisions, then re-add `guide:draft`."},
{author:"walker-tx",created_at:"2026-08-28T01:20:00Z",body:"## Guide factory failed\n\n- **Outcome:** failed\n\nResolve the findings, then re-add `guide:draft`."},
{author:"walker-tx",created_at:"2026-08-28T01:30:00Z",body:"## Pipeline review\n\n- **Outcome:** changes_requested\n- **Provider:** Box\n- **Run context:** resumed existing factory branch\n\n### Summary\n\nRevise.\n\nResolve the findings, then re-add `guide:draft`."},
{author:"bob",created_at:"2026-08-28T02:00:00Z",body:"## Scope check\nOperator evidence using a reserved heading."},
{author:"walker-tx",created_at:"2026-08-28T03:00:00Z",body:"## Pipeline review\n\n<!-- guide-factory-status -->\n\nLATEST_FACTORY_STATUS_CANARY"}
]' "$TMP/issue.json" >"$TMP/history.json"
bash "$ROOT/factory/scripts/inspect-inputs.sh" "$TMP/history.json" "$TMP/catalog.json" \
>"$TMP/history.out" 2>"$TMP/history.err"
jq -e '
[.issue.comments[].body] == [
"Operator evidence before retries.",
"## Scope check\nOperator evidence using a reserved heading.",
"## Pipeline review\n\n<!-- guide-factory-status -->\n\nLATEST_FACTORY_STATUS_CANARY"
]
' "$TMP/history.out" >/dev/null || fail 'input inspection did not bound generated factory history'
(( $(wc -c <"$TMP/history.out") < 8192 )) || fail 'bounded input inspection still spills generated history'
if grep -q 'OLD_FACTORY_HISTORY_CANARY' "$TMP/history.out" "$TMP/history.err"; then
fail 'input inspection retained stale generated factory history'
fi
assert_eq '' "$(cat "$TMP/history.err")"

printf '%s\n%s\n' "$(cat "$TMP/issue.json")" "$(cat "$TMP/issue.json")" >"$TMP/multiple.json"
if bash "$ROOT/factory/scripts/inspect-inputs.sh" "$TMP/multiple.json" "$TMP/catalog.json" >"$TMP/out" 2>"$TMP/err"; then
fail 'multiple issue documents unexpectedly succeeded'
Expand Down
Loading