Skip to content

fix(mobcode): handle triple-quoted Brython literals - #319

Merged
mrbdahlem merged 4 commits into
mainfrom
fix/mobcode-brython-triple-quote-indentation
Jul 31, 2026
Merged

fix(mobcode): handle triple-quoted Brython literals#319
mrbdahlem merged 4 commits into
mainfrom
fix/mobcode-brython-triple-quote-indentation

Conversation

@mrbdahlem

@mrbdahlem mrbdahlem commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of multiline Python string literals in the MobCode runner.
    • Preserved literal text, input() content, and indentation during execution.
  • Style

    • Improved workspace layout with fixed headers, viewport-aware sizing, editor scrolling, and sidebar scrolling.
    • Maintained responsive behavior on mobile devices.
  • Tests

    • Added automated coverage for multiline literals, runner output, scrolling, and workspace layout.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 25bed5cc-7c15-4e1f-8a3e-aff0a8ce8133

📥 Commits

Reviewing files that changed from the base of the PR and between 2789f15 and e96d82d.

📒 Files selected for processing (6)
  • .agent/knowledge/react-best-practices.md
  • .agent/knowledge/repo_discoveries.md
  • activities/mobcode/client/runner/runnerUtils.test.ts
  • activities/mobcode/client/runner/runnerUtils.ts
  • activities/mobcode/client/styles.css
  • activities/mobcode/playwright/runner.spec.ts

📝 Walkthrough

Walkthrough

The 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.

Changes

MobCode runner and layout updates

Layer / File(s) Summary
Literal classification
activities/mobcode/client/runner/runnerUtils.ts
The transformer tracks triple-quoted lines and excludes literal content from function, method, nested-block, import, and executable-code analysis.
Source transformation and validation
activities/mobcode/client/runner/runnerUtils.ts, activities/mobcode/client/runner/runnerUtils.test.ts, activities/mobcode/playwright/runner.spec.ts, .agent/knowledge/repo_discoveries.md
Literal-only lines remain unchanged. Wrapper indentation applies only when requested. Tests verify literal text, indentation, string values, and executable code on opening-delimiter lines.
Workspace and editor scrolling
activities/mobcode/client/styles.css, activities/mobcode/playwright/runner.spec.ts, .agent/knowledge/react-best-practices.md
The shell and workspace use viewport-constrained sizing. The sidebar and editor handle overflow within their panes. End-to-end coverage verifies fixed headers and editor scrolling.

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
Loading

Possibly related PRs

  • PerryHighCS/ActiveBits#274: Both changes modify runnerUtils.ts and its tests, but address different Brython source-transformation issues.
  • PerryHighCS/ActiveBits#314: Both changes modify buildBrythonAsyncEntrySource and add runner tests for Python source edge cases.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the MobCode fix for handling triple-quoted Brython literals, which is the main change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mobcode-brython-triple-quote-indentation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 528631a and 2789f15.

📒 Files selected for processing (4)
  • .agent/knowledge/repo_discoveries.md
  • activities/mobcode/client/runner/runnerUtils.test.ts
  • activities/mobcode/client/runner/runnerUtils.ts
  • activities/mobcode/playwright/runner.spec.ts

Comment thread activities/mobcode/client/runner/runnerUtils.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 literalLines is 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 rewriting input() / sleep() calls on that line, and it also prevents functionScopes tracking from seeing executable def/class lines 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.

Comment thread activities/mobcode/client/runner/runnerUtils.ts
Comment thread .agent/knowledge/repo_discoveries.md Outdated
Comment thread activities/mobcode/client/runner/runnerUtils.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

  • tripleQuotedStringLines treats any line encountered while quote is 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 in literalOnlyLines, so buildBrythonTransformedSource will 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
        }

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@mrbdahlem
mrbdahlem merged commit d68fa3d into main Jul 31, 2026
17 checks passed
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.

2 participants