""" The audit export never hands a spreadsheet a formula. It carries text a member chose — a refused blob's kind, a file name. A cell that starts with `=`, `+`, `-` or `@` runs as a formula when the operator opens the file, so it is given a leading apostrophe, which spreadsheets read as text. """ import json import shutil import subprocess from pathlib import Path import pytest CSV = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static" / "csv.js" pytestmark = pytest.mark.skipif(shutil.which("node") is None, reason="node unavailable") CASES = ['=HYPERLINK("http://x","y")', "+1+1", "-2+3", "@SUM(A1)", "\t=1", "plain", 'with "quotes"', "a,b", "", None, 12] def test_a_cell_is_text_and_quoted_where_it_must_be(tmp_path): script = tmp_path / "case.mjs" script.write_text( f"import {{ csvCell }} from '{CSV.as_uri()}';\n" f"console.log(JSON.stringify({json.dumps(CASES)}.map(csvCell)));\n") out = json.loads(subprocess.run(["node", str(script)], capture_output=True, text=True, check=True).stdout) assert out == ['"\'=HYPERLINK(""http://x"",""y"")"', "'+1+1", "'-2+3", "'@SUM(A1)", "'\t=1", "plain", '"with ""quotes"""', '"a,b"', "", "", "12"]