Skip to content

Commit d50b5fd

Browse files
authored
feat: weekly competitor feature watch (#507)
## What this does This adds a weekly feature watch to the competitor scan. Besides the README checks the scan already does, it now watches 11 specific doc sections on competitor sites (Mastra, MockServer and WireMock pages for tool mocks, MCP, recording, sessions and so on). For each source it extracts the named section, strips markup, hashes the text and runs a few keyword checks. It then compares the result with the last run. The last observed state lives in `scripts/competitive-watch-state.json`. It is committed empty (`{}`), so the first run records every source as `baseline`. Later runs report `no change`, or `changed` with the reason (section text changed, a check flipped false to true with the matching evidence, or the URL moved). The state is written together with the docs and before the summary, and nothing is written on a dry run. If any watched source can't be fetched, the run fails, names each failing source, and writes no summary, so a half-checked week never looks clean. Every scan summary now ends with a "## Feature watch" section: one row per source with its competitor, the claims it backs, its status, the reason, and any evidence. The workflow also counts a state-only change as a change. That opens a report-only PR ("Competitor feature-watch report", `chore:` commit) on a per-run branch, `auto/competitive-matrix-<date>-<run id>`. The Slack notification now carries the Feature watch section as a digest and the PR link, and it uses a separate message (🔎) when only the watch changed. A failed PR creation now reports as a failure instead of "PR created". The README scan also gets detection rules for MCP rows: MCP tool mocking, scenario-scoped MCP fixtures, and failing on undeclared or unmocked MCP tools. Each rule requires an actual MCP tool or server context near a mock word, with bounded proximity, so general text about mock servers or unmocked HTTP calls doesn't match. ## What this does not do The watch never edits the homepage matrix or the migration pages. Its results are only for human review in the PR body and the Slack digest. A watch change can't promote a cell to yes, partial or anything else; a person decides that after reading the evidence. A test proves that a watch-only change leaves the docs byte-identical. ## Reviewer note: live effect of the first run The first scheduled run after merge will flip two public cells for mock-llm, because its README documents MCP mocking and the new rule detects it: - Homepage matrix: mock-llm / "MCP tool mocking" goes from ✗ to ✓. - `docs/migrate-from-mock-llm/`: "MCP protocol mocking" goes from ✗ to ✓. Both flips come from this PR. A real dry run against the live READMEs shows exactly those two mock-llm changes plus older piyook flips that also appear on main without this PR. Please confirm the mock-llm cells are correct before you merge the first report PR. ## Red-green evidence Each step was proven on the real surface (live READMEs and doc pages, or the workflow's own `run:` text in a local harness), plus unit tests. - **MCP rules.** RED: a real dry-run scan on main finds no MCP feature for any competitor, and the new unit tests fail 3 of 4. GREEN: the same scan detects "MCP tool mocking" for mock-llm (`No -> Yes`, the only new flip), and the tests pass 4 of 4. - **Watch module.** RED: running `scripts/competitive-watch.ts` on main fails with module not found. GREEN: two live runs record all 11 sources as `baseline` with identical hashes. A source forced to a closed port fails the run with `ECONNREFUSED` and names the source (exit 1). - **Scan integration.** RED: on main the summary has no "## Feature watch" section and `--watch-state` is ignored, and 13 new unit cases fail. GREEN: the dry run ends the summary with 11 baseline rows and writes no state. The real run writes the state after the docs and before the summary. A forced fetch failure exits 1 with no summary. Mutating the write order or the headline logic turns the tests red. - **Workflow.** RED: on main, `actionlint` reports two SC2086 findings. In the harness, a state-only change is dropped (`changed=false`), and a failed PR creation still posts "PR created". GREEN: `actionlint` and `zizmor` are clean. A state-only change opens a report PR on a per-run branch, and Slack carries the digest and PR link. A failed PR creation posts ❌. - **Value check (end to end).** Three local runs follow the spec's sequence. Run 1 on the empty seed records 11 baseline. Run 2 records 11 `no change`, the state stays byte-identical, and the workflow skips the PR and posts ✅. Run 3, after one hash is edited, shows `mockserver-ap-mcp` as changed, and the workflow opens a report-only PR whose 🔎 digest names that source. A consumer proof added a new watch entry in a scratch tree. It went red without the entry and green with it, and the homepage was not promoted. - **Surgical fix.** RED: with the earlier MCP rules, 7 false-positive probes matched (for example "Unmocked requests fail with a 404", "By default, unmocked HTTP calls are denied", "Run the mock server MCP endpoint", "mockserver mcp support"). GREEN: all 7 are rejected, and the live mock-llm README is still detected. In the workflow harness, the old Create PR step listed and closed an older report PR. After the fix it makes no `gh pr list` or `gh pr close` calls. ## Review This went through three review rounds, then a surgical fix. Rounds 1 and 2 produced fixes that were folded into these commits. Round 3 was stopped once scope was narrowed to the two reproduced, load-bearing defects. The surgical fix tightened the three MCP keyword rules after seven false-positive probes were confirmed red then green, as shown above. It also removed the step that auto-closed superseded report PRs, because that step could close an older report PR that carried a real matrix change. Before push, format, lint, typecheck, build and the full suite all passed (309 files, 10318 tests). `actionlint` and `zizmor` are clean on the workflow. ## Known follow-ups - With real data, the scan PR headline never mentions the feature watch, because rowless detections and manual checks are always present. Only the "## Feature watch" section and Slack show it. We need to decide whether the manual-check headline names watch changes too. - Since the supersede-close step was removed, duplicate open report PRs can pile up from week to week. - Shared helpers (cell escaping, flag parsing, error text with cause, HTML to text) are repeated across the scripts. They can move into a `scripts/lib` module. - Workflow hardening (all pre-existing behavior): the branch is pushed before `gh pr create`, so a failed create leaves an orphan branch. The failure Slack message doesn't say what failed. A run cancelled by `cancel-in-progress` posts "update failed".
2 parents 7062bdc + 08ae1af commit d50b5fd

13 files changed

Lines changed: 3379 additions & 102 deletions

‎.github/workflows/update-competitive-matrix.yml‎

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ jobs:
3737
- name: Check for changes
3838
id: changes
3939
run: |
40-
if git diff --quiet docs/; then
41-
echo "changed=false" >> $GITHUB_OUTPUT
40+
# Use git status, not git diff: it also sees untracked files, e.g. a
41+
# new docs page. (A missing state file is not re-created: the scan
42+
# fails the run instead.)
43+
if [ -n "$(git status --porcelain -- docs/ scripts/competitive-watch-state.json)" ]; then
44+
echo "changed=true" >> "$GITHUB_OUTPUT"
4245
else
43-
echo "changed=true" >> $GITHUB_OUTPUT
46+
echo "changed=false" >> "$GITHUB_OUTPUT"
47+
fi
48+
if [ -n "$(git status --porcelain -- docs/)" ]; then
49+
echo "docs_changed=true" >> "$GITHUB_OUTPUT"
50+
else
51+
echo "docs_changed=false" >> "$GITHUB_OUTPUT"
4452
fi
4553
4654
- name: Configure git credentials
@@ -50,42 +58,104 @@ jobs:
5058
git config --local url."https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
5159
5260
- name: Create PR
61+
id: pr
5362
if: steps.changes.outputs.changed == 'true'
5463
env:
5564
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
RUN_ID: ${{ github.run_id }}
66+
DOCS_CHANGED: ${{ steps.changes.outputs.docs_changed }}
5667
run: |
5768
git config user.name "github-actions[bot]"
5869
git config user.email "github-actions[bot]@users.noreply.github.com"
59-
BRANCH="auto/competitive-matrix-$(date +%Y%m%d)"
70+
# The run id keeps two runs on the same day on separate branches.
71+
BRANCH="auto/competitive-matrix-$(date +%Y%m%d)-${RUN_ID}"
6072
git checkout -b "$BRANCH"
61-
git add docs/
62-
git commit -m "docs: update competitive matrix and migration pages from latest competitor data"
73+
git add docs/ scripts/competitive-watch-state.json
74+
if [ "$DOCS_CHANGED" = "true" ]; then
75+
TITLE="Update competitive matrix and migration pages"
76+
git commit -m "docs: update competitive matrix and migration pages from latest competitor data"
77+
else
78+
TITLE="Competitor feature-watch report"
79+
git commit -m "chore: update competitor feature-watch state"
80+
fi
6381
git push -u origin "$BRANCH"
64-
gh pr create \
65-
--title "Update competitive matrix and migration pages" \
82+
PR_URL=$(gh pr create \
83+
--title "$TITLE" \
6684
--body-file /tmp/matrix-summary.md \
67-
--base main
85+
--base main)
86+
echo "url=${PR_URL}" >> "$GITHUB_OUTPUT"
6887
6988
- name: Notify Slack
7089
if: always()
7190
env:
7291
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
7392
CHANGED: ${{ steps.changes.outputs.changed }}
93+
DOCS_CHANGED: ${{ steps.changes.outputs.docs_changed }}
94+
PR_URL: ${{ steps.pr.outputs.url }}
7495
JOB_STATUS: ${{ job.status }}
7596
RUN_ID: ${{ github.run_id }}
7697
run: |
7798
if [ -z "$SLACK_WEBHOOK" ]; then echo "SLACK_WEBHOOK not set, skipping"; exit 0; fi
78-
if [ "$CHANGED" = "true" ]; then
99+
# "PR created" only when the PR step really produced a URL; a failed
100+
# Create PR falls through to the failure message.
101+
if [ "$CHANGED" = "true" ] && [ -n "$PR_URL" ] && [ "$DOCS_CHANGED" = "true" ]; then
79102
EMOJI="📊"
80103
MSG="*Competitive matrix changes detected* — PR created with updated migration pages. <https://github.com/CopilotKit/aimock/actions/runs/${RUN_ID}|View run>"
104+
elif [ "$CHANGED" = "true" ] && [ -n "$PR_URL" ]; then
105+
EMOJI="🔎"
106+
MSG="*Competitor feature-watch changes need a review* — report PR created. <https://github.com/CopilotKit/aimock/actions/runs/${RUN_ID}|View run>"
81107
elif [ "$JOB_STATUS" = "success" ]; then
82108
EMOJI="✅"
83109
MSG="Competitive matrix check — no changes detected."
84110
else
85111
EMOJI="❌"
86112
MSG="*Competitive matrix update failed*. <https://github.com/CopilotKit/aimock/actions/runs/${RUN_ID}|View run>"
87113
fi
88-
PAYLOAD=$(jq -n --arg text "${EMOJI} ${MSG}" '{text: $text}')
89-
curl -s -X POST "$SLACK_WEBHOOK" \
90-
-H "Content-Type: application/json" \
91-
-d "$PAYLOAD"
114+
# The digest is the summary's "## Feature watch" section. It is sent
115+
# only with a created PR, so a quiet week, a failed Create PR and a
116+
# failed run send none (the full table is in the PR body).
117+
: > /tmp/feature-watch.md
118+
if [ -n "$PR_URL" ] && [ -f /tmp/matrix-summary.md ]; then
119+
awk '/^## /{inwatch = ($0 == "## Feature watch")} inwatch' /tmp/matrix-summary.md > /tmp/feature-watch.md
120+
fi
121+
# jq turns the GFM digest into Slack mrkdwn: the heading becomes bold
122+
# and each table row becomes one bullet. Each cell is decoded back to
123+
# the text the script had before its GFM `cell()` escaping: the row
124+
# splits only on a "|" that is not backslash-escaped (no placeholder
125+
# characters, so competitor control characters cannot collide), each
126+
# "\" escape is removed, the U+2060 after "@" and "#" and before "$" is
127+
# dropped, and "&lt;", "&gt;" and "&amp;" are decoded in one pass.
128+
# Then the digest
129+
# (and only the digest: the "View run" link above stays live) is
130+
# escaped for Slack once, so competitor text such as <!channel> or
131+
# <url|label> is inert and shows as written.
132+
PAYLOAD=$(jq -n \
133+
--arg text "${EMOJI} ${MSG}" \
134+
--arg pr "${PR_URL}" \
135+
--rawfile watch /tmp/feature-watch.md \
136+
'def slack: gsub("&"; "&amp;") | gsub("<"; "&lt;") | gsub(">"; "&gt;");
137+
def plain: gsub("\\\\(?<c>.)"; .c)
138+
| gsub("(?<c>[@#])⁠"; .c)
139+
| gsub("⁠(?<c>[$])"; .c)
140+
| gsub("&(?<e>amp|lt|gt);"; {amp: "&", lt: "<", gt: ">"}[.e]);
141+
def cells: [scan("\\\\.?|\\||[^\\\\|]+")]
142+
| reduce .[] as $t ([""]; if $t == "|" then . + [""] else .[-1] += $t end)
143+
| .[1:-1] | map(sub("^ +"; "") | sub(" +$"; ""));
144+
def row: cells as $c
145+
| ((($c[0] // "") | capture("^\\[(?<id>.*)\\]\\(.*\\)$") | .id) // $c[0]) as $id
146+
| "• *" + ($id | plain) + "* (" + ($c[1] | plain) + "; " + ($c[2] | plain) + "): "
147+
+ ($c[3] | plain)
148+
+ (if $c[4] != "-" then " — Details: " + ($c[4] | plain) else "" end)
149+
+ (if $c[5] != "-" then " — Evidence: " + ($c[5] | plain) else "" end);
150+
def digest: split("\n")
151+
| map(if startswith("## ") then "*" + ltrimstr("## ") + "*"
152+
elif test("^\\| (Source|---) \\|") then empty
153+
elif startswith("| ") then row
154+
else . end)
155+
| join("\n") | slack;
156+
{text: ($text
157+
+ (if $pr != "" then "\n" + $pr else "" end)
158+
+ (if $watch != "" then "\n\n" + ($watch | digest) else "" end))}')
159+
# The webhook is a secret: keep its curl on one line, behind the guard above.
160+
# --fail-with-body makes a rejected post (4xx/5xx) fail the step and log Slack's reason.
161+
curl -sS --fail-with-body -X POST "$SLACK_WEBHOOK" -H "Content-Type: application/json" -d "$PAYLOAD"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)