Skip to content

Fix Wrong Answer for problems with top-level JSON string output - #15

Open
alexandramartinez wants to merge 1 commit into
bighnesh0007:masterfrom
alexandramartinez:fix/json-string-output-quotes
Open

Fix Wrong Answer for problems with top-level JSON string output#15
alexandramartinez wants to merge 1 commit into
bighnesh0007:masterfrom
alexandramartinez:fix/json-string-output-quotes

Conversation

@alexandramartinez

Copy link
Copy Markdown
Collaborator

Summary

Fixes #12 — problems whose expected output is a top-level JSON string (e.g. concatenate-employee-names) were impossible to solve. Submit always returned "Wrong Answer" because the actual output was shown with its surrounding quotes stripped, so it never matched the quoted expected value.

Root cause

The backend at dwlbackend.onrender.com returns output as the decoded value, not serialized text:

  • application/json → a real JSON value ({"output":"Alice, Bob, Carol"}, {"output":3}, {"output":{...}})
  • non-JSON formats (application/csv, xml, …) → the already-rendered text as a string

The proxy in app/api/execute/route.ts did typeof value === "string" ? value : JSON.stringify(value), so a top-level JSON string was passed through unquoted. The submit comparison in Workspace.tsx then re-serialized the quoted expected value but kept the unquoted actual value — never equal.

Fix

Serialize based on the script's declared output format:

  • JSON output → always JSON.stringify the value, so a top-level string keeps its quotes ("Alice, Bob, Carol").
  • Non-JSON output (csv/xml/text) → pass string values through verbatim, since the backend already rendered them.

Verification

Tested end-to-end against a local dev server with the real problem seeded into MongoDB, driving the actual /api/execute route and the real normalize() comparison from Workspace.tsx:

Before (reproduces the bug):

✗ Wrong Answer
Test 1: ✗ Failed   Expected: "Alice, Bob, Carol"   Got: Alice, Bob, Carol
Test 2: ✗ Failed   Expected: "Dave"                Got: Dave

After:

✅ Accepted
Test 1: ✓ Passed   Expected: "Alice, Bob, Carol"   Got: "Alice, Bob, Carol"
Test 2: ✓ Passed   Expected: "Dave"                Got: "Dave"

No regressions confirmed against live backend responses:

Output Result
JSON string "Alice, Bob, Carol" (quoted) ✓
JSON number 3
JSON object pretty-printed object ✓
CSV a,b\n1,2 (raw, no quotes) ✓

npx tsc --noEmit passes clean.

🤖 Generated with Claude Code

The execute proxy returned the backend's decoded `output` value verbatim
when it was a string, so a top-level JSON string lost its surrounding
quotes (e.g. `Alice, Bob, Carol` instead of `"Alice, Bob, Carol"`). The
submit comparison then re-serialized the quoted expected value but kept
the unquoted actual value, making any string-output problem unsolvable.

Serialize based on the script's declared `output` format: JSON output is
always JSON.stringify'd (so strings keep their quotes), while non-JSON
formats (csv, xml, ...) pass their already-rendered text through unchanged.

Fixes bighnesh0007#12

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

@alexandramartinez is attempting to deploy a commit to the bighnesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dwcode Ready Ready Preview, Comment Jul 17, 2026 6:18pm

@f-schnabel f-schnabel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

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.

Submit always returns "Wrong Answer" for problems with a top-level JSON string output (quotes stripped from actual output)

2 participants