Skip to content

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

Description

@alexandramartinez

Summary

Problems whose expected output is a top-level JSON string always fail with "Wrong Answer" on submit, even when the user's DataWeave is correct. The console shows the "Got" value with its surrounding quotes stripped, so it never matches the quoted "Expected" value.

Reproduced on: https://dwcode.vercel.app/problems/concatenate-employee-names

Reproduction

Code:

%dw 2.0
output application/json
---
payload joinBy ", "

Input:

["Alice", "Bob", "Carol"]

Result:

✗ Wrong Answer

Test 1: ✗ Failed
  Expected: "Alice, Bob, Carol"
  Got:      Alice, Bob, Carol

Test 2: ✗ Failed
  Expected: "Dave"
  Got:      Dave

The correct application/json output of a string value is "Alice, Bob, Carol" with quotes, so the expected value is right — the actual/"Got" value is what's wrong (missing quotes).

Root cause

Two related spots:

1. app/api/execute/route.ts (lines ~77-79) — when the backend returns a string, it's passed through verbatim instead of being JSON-encoded:

output: typeof (data.output ?? data.result) === "string"
  ? (data.output ?? data.result)              // <-- returns `Alice, Bob, Carol`, no quotes
  : JSON.stringify(data.output ?? data.result, null, 2),

For output application/json, a top-level string result should be serialized as "Alice, Bob, Carol" (quoted). Because the already-deserialized string value is returned as-is, the surrounding quotes are lost.

2. app/problems/[slug]/Workspace.tsx (lines ~213-224) — the comparison normalizer is asymmetric:

const normalize = (s: string) => {
  try {
    return JSON.stringify(JSON.parse(s.trim()));
  } catch {
    return s.trim();
  }
};

const actual = normalize(tcData.output);       // `Alice, Bob, Carol` -> JSON.parse throws -> stays unquoted
const expected = normalize(tc.expectedOutput); // `"Alice, Bob, Carol"` -> parses -> re-stringified WITH quotes
const passed = actual === expected;            // never equal
  • expectedOutput = "Alice, Bob, Carol" is valid JSON → JSON.parse succeeds → JSON.stringify yields "Alice, Bob, Carol" (quotes kept).
  • tcData.output = Alice, Bob, Carol is not valid JSON → JSON.parse throws → falls back to the raw unquoted string.

So the normalized forms can never be equal, and any problem with a top-level string output is unsolvable.

Impact

Every problem whose expected answer is a JSON string (not an object/array) is impossible to pass, regardless of correct code. concatenate-employee-names is one confirmed example.

Suggested fix

Fix the primary cause in the execute proxy so a top-level string is JSON-encoded when the backend indicates a JSON output (e.g. JSON.stringify(value) for string results under application/json). That makes "Got" show "Alice, Bob, Carol" and the existing normalizer will then match. Optionally, make the normalize() helper symmetric so a parse failure on one side doesn't silently produce a mismatch.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions