fix(mobcode): handle triple-quoted Brython literals - #319
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe Brython source transformer now preserves triple-quoted string contents during analysis and execution. MobCode layout rules constrain viewport overflow and editor scrolling. Unit, end-to-end, and repository knowledge coverage document both changes. ChangesMobCode runner and layout updates
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant PythonSource
participant runnerUtils
participant Brython
PythonSource->>runnerUtils: source with triple-quoted literals
runnerUtils->>runnerUtils: classify literal and executable lines
runnerUtils->>Brython: transformed source with preserved literal contents
Brython-->>runnerUtils: execute transformed source
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@activities/mobcode/client/runner/runnerUtils.ts`:
- Around line 492-496: Update topLevelPythonBlocks to accept rewriteBareSleep as
a parameter and remove its internal importsTimeSleep(lines.filter(...))
computation. Pass the already computed rewriteBareSleep from
buildBrythonTransformedSource at the existing call site, preserving the current
behavior while eliminating the duplicate scan.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c32a1ad5-0452-4349-a66c-d5ae40899b38
📒 Files selected for processing (4)
.agent/knowledge/repo_discoveries.mdactivities/mobcode/client/runner/runnerUtils.test.tsactivities/mobcode/client/runner/runnerUtils.tsactivities/mobcode/playwright/runner.spec.ts
There was a problem hiding this comment.
Pull request overview
This PR updates MobCode’s Brython Python runner source transformation to better handle triple-quoted (multiline) string literals, preventing line-oriented rewrites (e.g., input() → await mobcode_input(...)) and wrapper indentation from altering literal content. It also adds unit and Playwright coverage to validate that multiline literal text and indentation are preserved end-to-end in the runner UI.
Changes:
- Added a triple-quoted literal line classifier and used it to skip statement/block detection and call rewrites for literal-only lines.
- Adjusted top-level block detection to ignore literal-only lines when determining function/class structure and
input()presence. - Added unit + Playwright tests covering preservation of triple-quoted literal content and indentation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| activities/mobcode/playwright/runner.spec.ts | Adds Playwright regressions ensuring printed triple-quoted literal text is not rewritten and indentation-dependent values remain correct. |
| activities/mobcode/client/runner/runnerUtils.ts | Introduces triple-quote line classification and integrates it into the Brython source transform (indent/scoping/rewrite decisions). |
| activities/mobcode/client/runner/runnerUtils.test.ts | Adds unit tests asserting the async-entry source wrapping preserves triple-quoted literal content/values. |
| .agent/knowledge/repo_discoveries.md | Records the triple-quoted literal handling discovery for future contributors/agents. |
Comments suppressed due to low confidence (1)
activities/mobcode/client/runner/runnerUtils.ts:594
- Currently any line in
literalLinesis skipped from rewriting entirely, including the opening triple-quote line that may contain executable code before/after the delimiter (and is explicitly called out as executable in the helper). This can miss rewritinginput()/sleep()calls on that line, and it also preventsfunctionScopestracking from seeing executabledef/classlines that include an inline docstring (def f(): """doc"""). At minimum, only skip literal-only lines (i.e. those that do not require wrapper indentation).
const transformedLines = lines.map((line, lineIndex) => {
if (literalLines.has(lineIndex)) return line
const trimmed = line.trim()
if (!trimmed || trimmed.startsWith('#')) return line
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (1)
activities/mobcode/client/runner/runnerUtils.ts:218
tripleQuotedStringLinestreats any line encountered whilequoteis active as a literal-only line unless it was the opening delimiter line. If the closing delimiter line also contains executable code after the'''/"""(e.g."""; sleep(0)), that line ends up inliteralOnlyLines, sobuildBrythonTransformedSourcewill skip rewrites and (for async entry) skip wrapper indentation—producing invalid Python indentation once the string closes.
At minimum, detect trailing non-comment text after a closing delimiter and mark the line as requiring wrapper indentation (a more complete solution would indent only the suffix after the delimiter to preserve literal value).
if (nextThree === quote.repeat(3)) {
index += 3
quote = null
continue
}
Summary by CodeRabbit
Bug Fixes
input()content, and indentation during execution.Style
Tests