Skip to content

Require real copy evidence before promoting a control to copy-to-clipboard - #7469

Merged
chubes4 merged 1 commit into
trunkfrom
fix/copy-to-clipboard-evidence
Nov 24, 2026
Merged

chubes4 merged 1 commit into
trunkfrom
fix/copy-to-clipboard-evidence

Conversation

@chubes4

@chubes4 chubes4 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7467

What

A control now needs real copy evidence before CopyToClipboardConverter promotes it to the copy-to-clipboard block:

  • Clipboard contract: data-clipboard* (clipboard.js) or data-copy-text / -target / -selector / -value / -content, which name the copied payload.
  • Clipboard handler, or a copy-intent accessible name: unchanged.
  • Script-bound data-copy*: any other data-copy* attribute, including a bare data-copy, counts only when a source runtime script (runtime_projection_script_assets) writes to the clipboard (clipboard.writeText/write, or execCommand('copy')) close to where it reads that attribute (data-copy or dataset.copy…).

Anything else, such as a quantity stepper + with data-copy="block-0" and "Add one Cutlery bay", is not handled by this converter. It falls through to ordinary button lowering, the same path its − sibling already takes. There is no stepper primitive in the engine today.

Root cause: php-transformer/src/HtmlToBlocks/Elements/CopyToClipboardConverter.php hasClipboardContract() matched /^data-(?:clipboard|copy)(?:-[a-z0-9-]+)?$/ as copy evidence by itself. That rule was introduced in #2051.

Tests

tests/unit/copy-to-clipboard-block.php adds three cases:

  • A stepper with no script is not a copy block and keeps its native button and accessible name. This fails on trunk.
  • The same stepper with a configurator script that duplicates on dataset.copy is still not a copy block, even though the script calls navigator.clipboard.writeText elsewhere for an unrelated share link.
  • data-copy that a script feeds to navigator.clipboard.writeText(b.dataset.copy) is still a copy block, and the attribute supplies the payload.

Verification

  • tests/unit/copy-to-clipboard-block.php: passes (fails on trunk)
  • phpcs and phpstan: clean
  • php tests/run.php: the only failures are Chrome-dependent contracts that also fail on trunk locally (no Chrome)
  • Parity suite: 368 fixtures pass
  • End to end, with this branch and Keep classes a generated block's save() writes when publishing class names #7468 packaged into Static Site Importer and the Bossa capture subset imported into a scratch Studio site, build-your-drawer has 0 copy-to-clipboard blocks (5 before). Its five + steppers are core/buttons lowered exactly like their − siblings, and editor validation reports 0 invalid blocks site-wide.

AI disclosure: implemented by Claude (Opus) as a Franklin/Pi subagent; Chris Huber directed the work.

…ontrol to copy-to-clipboard

A bare data-copy attribute was copy evidence by itself, but data-copy also
names duplicate and clone commands: a configurator's quantity stepper
(data-copy="block-0", "Add one Cutlery bay") became a copy button that
copied "block-0".

Clipboard contracts are now data-clipboard* and data-copy-{text,target,
selector,value,content}. Any other data-copy* attribute counts only when
a source runtime script writes to the clipboard where it reads that
attribute. Otherwise the control keeps ordinary button lowering.

Fixes #7467
@chubes4

chubes4 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

import-loop/corpus "worse on sdnunca (3)" is replay noise. This PR does not change sdnunca's output.

Can this PR affect sdnunca at all? No. The frozen capture (~/Studio/loop-runs/corpus/sdnunca/capture on homeboy-lab: 45 HTML files, 3 JS files, 23 CSS files) has zero matches for data-copy, data-clipboard, clipboard or execCommand, and no button has a "copy" label. The only paths this PR changes (hasClipboardContract narrowing and hasScriptBoundCopyAttribute) run only on elements that have a data-copy* attribute. sdnunca has none.

Output diff. I replayed sdnunca with corpus.mjs replay against the same baseline the status used (.baselines/8cfa511d38dc-v1.38.26, trunk 8cfa511d38dc, SSI v1.38.26). I ran trunk and this head (this PR's CopyToClipboardConverter.php on that trunk) 3 rounds each and kept the imported sites:

  • wp_posts content (33 rows: 5 pages, 4 navigations, 24 attachments): all 6 dumps are byte-identical (sha256 7e995d98…), trunk vs head and across rounds. None contains a copy-to-clipboard block.
  • Generated theme files (templates, parts, theme.json, CSS): byte-identical across all 6. The only difference is static-site-importer-manifest.json, and only in per-run fields (import_run_id, imported_at, the run path, and the per-route content_hash derived from them). Trunk differs from trunk in those same fields between rounds. With those fields normalized, all 6 manifests are identical.

Visual replay vs baseline (regressed cells):

round trunk 8cfa511 (no PR) this head
1 /privacy-policy/@390, /privacy-policy/@1440 (+@1440 unmeasured) none
2 /@390 none
3 none /@1440

Trunk "regresses" against its own baseline in 2 of 3 rounds, so the sdnunca cells flip with machine load. The same flakiness shows up on unrelated heads: sdnunca was flagged on #7449, #7456 and #7461, and could not be measured on #7455, #7464 and #7468.

The 3 specific cells from the original run aren't recoverable: the import-corpus-pr step's stdout was not persisted (instance wf-import-corpus-pr-d8820357f12b, no output.json). The results above don't depend on which cells they were, because the generated markup is identical.

No code change is needed for this PR.

AI disclosure: investigated by Claude (Opus) as a Franklin/Pi subagent; Chris Huber directed the work.

@chubes4
chubes4 merged commit 02983fa into trunk Nov 24, 2026
14 of 15 checks passed
@chubes4
chubes4 deleted the fix/copy-to-clipboard-evidence branch November 24, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy-to-clipboard treats a bare data-copy attribute as clipboard evidence, so quantity steppers become copy buttons

1 participant