Skip to content

Match add_repl values only as whole alphanumeric runs - #7949

Open
denik wants to merge 2 commits into
mainfrom
denik/add-repl-whole-word
Open

denik wants to merge 2 commits into
mainfrom
denik/add-repl-whole-word

Conversation

@denik

@denik denik commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Changes

add_repl literals now match only as whole alphanumeric runs. A literal whose first or last byte is an ASCII letter or digit must have a non-alphanumeric neighbour on that side (or the start or end of the text). Other characters, including _, -, /, . and :, are separators. Sides that start or end with a non-alphanumeric character keep the old behaviour.

The Go harness (libs/testdiff, loadScriptReplacements) and acceptance/bin/repls.py apply the same rule. Literals set by the harness through Set keep plain substring matching, so paths and versions are unchanged.

Why

Scripts register IDs with add_repl, and those replacements are applied before the harness patterns. Because the match was a plain substring, a short ID could also match inside another token. In a real DMS run, a deployment ID was a substring of the CLI's embedded commit hash, so the [CLI_VERSION]+<hash> cleanup no longer matched and the output showed a mangled version. The same class of collision came up for a dependency-test ID inside another ID. Test servers can avoid this by using long IDs, but real DMS and cloud IDs are not under our control.

Tests

  • Unit tests in libs/testdiff/replacement_test.go cover: inside a hex string, standalone, job_<id>, deploy-<id>, /<id>/, adjacent <id>,<id>, values starting or ending with a non-alphanumeric character, a rejected match that does not hide a later one, and the JSON-encoded variant. A test also checks that harness Set literals still match inside longer strings.
  • repls.py doctests cover the same rule (python3 -m doctest acceptance/bin/repls.py).
  • New selftest acceptance/selftest/add_repl_word registers an ID and checks it inside a hex string, next to _, -, / and , separators, and compares two files with diff.py, which runs the Python path.
  • The full local acceptance suite is in progress. Golden diffs will be reviewed before any regeneration.

This pull request and its description were written by Isaac.

add_repl registers a plain substring match, so a short ID can cut into a
longer token in test output: a deployment ID inside an embedded commit hash
hid the CLI version cleanup pattern in a real DMS run.

A literal whose first or last byte is an ASCII letter or digit now matches
only where its neighbour on that side is not an ASCII letter or digit. The
Go harness (libs/testdiff) and acceptance/bin/repls.py apply the same rule.
Harness-set literals (Set) keep plain substring matching.

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Commit: 6cb522ff3 | Workflow run

Regression test report

Selected 1 changed tests (limit=20, 0 not selected)

3 tests: regression=0 unreleased=0 coverage=3 failing=0
test branch main (c639f9d) latest (v1.28.0)
TestAccept/bundle/dms/depends-on/DMS=true ✅ ✅ ✅
TestAccept/bundle/dms/no-drift/DMS=true ✅ ✅ ✅
TestAccept/selftest/add_repl_word ✅ ✅ ✅

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 6cb522f

Run: 45510419566

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 276 20 5:06
💚​ aws-windows-latest-4core-16gb 1 278 18 4:15
💚​ azure linux-2core-8gb 1 275 20 4:59
💚​ azure-windows-latest-4core-16gb 1 277 18 3:59
💚​ gcp linux-2core-8gb 1 276 20 4:41
💚​ gcp-windows-latest-4core-16gb 1 278 18 4:10
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:06 azure linux-2core-8gb TestAccept
3:51 aws linux-2core-8gb TestAccept
3:48 aws-windows-latest-4core-16gb TestAccept
3:33 azure-windows-latest-4core-16gb TestAccept
3:30 gcp-windows-latest-4core-16gb TestAccept
3:22 gcp linux-2core-8gb TestAccept

cloud: TestAccept/bundle/dms/no-drift TestAccept/bundle/dms/depends-on

Co-authored-by: Isaac <no-reply@databricks.com>
@denik
denik marked this pull request as ready for review November 24, 2026 23:50
@denik
denik requested a review from a team as a code owner November 24, 2026 23:50

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at 6cb522f. Each finding was verified against the code.

No blocking issues found. 3 non-blocking comment(s) and 1 question(s) below.

This PR makes add_repl literals match only as whole alphanumeric runs, in both the Go harness (replaceWholeWord) and repls.py, so a short script-registered ID no longer cuts into a commit hash or a longer ID. I didn't find a bug in the Go or Python matching logic, and the two apply the same rule. The new selftest doesn't actually check the Python path it says it covers, and it doesn't follow two of the testing rules.

Questions

  1. This changes matching for every add_repl, replace_ids.py and read_id.py literal in the suite, and the description says the full acceptance run is still in progress. A golden where a registered value sits directly next to a letter or digit would silently stop being replaced. Can you post which goldens change, or confirm that none do, before merging? (non-blocking)

echo "job $job_id, commit 33939489e027, number 3390"
echo "job_$job_id deploy-$job_id /$job_id/ $job_id,$job_id"

# diff.py applies the same replacements in Python. The files are equal only if the ID is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] This check passes even if literal_pattern goes back to re.escape(value). Both files contain 33939489e027, so the old rule turns both lines into job [SHORT_ID] commit [SHORT_ID]39489e027. They still compare equal and the golden still only shows diff done, which also makes the comment above wrong. Can you make the Python result visible? For example, put the hash only in a.txt and write the old mangled form [SHORT_ID]39489e027 in b.txt, so the old rule prints no diff and the new rule prints one. Or make the files differ elsewhere, so diff.py prints already-replaced lines into the golden.


# diff.py applies the same replacements in Python. The files are equal only if the ID is
# not replaced inside the commit hash.
echo "job 339 commit 33939489e027" > a.txt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] a.txt and b.txt have fixed contents, and .agents/rules/testing.md says to commit static test inputs into the test directory rather than create them in script. Can you commit them and drop the echo > lines and the rm on line 13?

@@ -0,0 +1,14 @@
job_id=339

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] acceptance/selftest/add_repl/ already tests add_repl replacement of a job ID. .agents/rules/testing.md asks to extend the existing acceptance directory when coverage overlaps. Could these whole-word cases go there instead of a new add_repl_word/?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants