add version identifier to csv

This commit is contained in:
Golumpa 2026-06-17 17:02:40 +01:00
parent 49499f10e3
commit 9b37d0a747
2 changed files with 18 additions and 1 deletions

View file

@ -4,7 +4,10 @@ import csv
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from nte_history_exporter import __version__
FIELDNAMES = [ FIELDNAMES = [
"exporter_version",
"uid", "uid",
"uid_status", "uid_status",
"export_record", "export_record",
@ -54,4 +57,4 @@ def write_csv(path: str | Path, rows: list[dict[str, Any]]) -> None:
with Path(path).open("w", newline="", encoding="utf-8") as f: with Path(path).open("w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=FIELDNAMES, extrasaction="ignore") writer = csv.DictWriter(f, fieldnames=FIELDNAMES, extrasaction="ignore")
writer.writeheader() writer.writeheader()
writer.writerows(rows) writer.writerows({**row, "exporter_version": __version__} for row in rows)

View file

@ -4,6 +4,7 @@ import sys
import unittest import unittest
from pathlib import Path from pathlib import Path
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from tempfile import TemporaryDirectory
ROOT = Path(__file__).resolve().parents[1] ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src" SRC = ROOT / "src"
@ -13,6 +14,7 @@ ARC_EXPORTS = EXPORTS / "arc"
if str(SRC) not in sys.path: if str(SRC) not in sys.path:
sys.path.insert(0, str(SRC)) sys.path.insert(0, str(SRC))
from nte_history_exporter import __version__
from nte_history_exporter.decoder.boundary import annotate_groups, make_uid from nte_history_exporter.decoder.boundary import annotate_groups, make_uid
from nte_history_exporter.constants import LIMITED_CHARACTER_MARKER, MARKER from nte_history_exporter.constants import LIMITED_CHARACTER_MARKER, MARKER
from nte_history_exporter.decoder.boundary import select_continuous_run_from_page_1 from nte_history_exporter.decoder.boundary import select_continuous_run_from_page_1
@ -21,6 +23,7 @@ from nte_history_exporter.constants import POOL_META
from nte_history_exporter.mappings import ARC_META, CHARACTERS, ITEMS, REWARDS_BY_ID from nte_history_exporter.mappings import ARC_META, CHARACTERS, ITEMS, REWARDS_BY_ID
from nte_history_exporter.decoder.protocol import decode_reward_key, infer_reward_type from nte_history_exporter.decoder.protocol import decode_reward_key, infer_reward_type
from nte_history_exporter.decoder.user_uid import extract_user_uid from nte_history_exporter.decoder.user_uid import extract_user_uid
from nte_history_exporter.export.csv_export import write_csv
from nte_history_exporter.decoder.arc import ( from nte_history_exporter.decoder.arc import (
arc_request_page, arc_request_page,
build_arc_rows_from_pairs, build_arc_rows_from_pairs,
@ -393,6 +396,17 @@ class BoundaryExportTests(unittest.TestCase):
self.assertEqual(export["capture_source"], "npcap") self.assertEqual(export["capture_source"], "npcap")
self.assertEqual(export["user_uid"], "123456789") self.assertEqual(export["user_uid"], "123456789")
def test_debug_csv_includes_exporter_version(self):
with TemporaryDirectory() as tmp:
path = Path(tmp) / "debug.csv"
write_csv(path, [{"uid": "abc123"}])
with path.open(newline="", encoding="utf-8") as f:
rows = list(csv.DictReader(f))
self.assertEqual(rows[0]["exporter_version"], __version__)
self.assertEqual(rows[0]["uid"], "abc123")
def test_export_paths_include_user_uid_banner_and_timestamp(self): def test_export_paths_include_user_uid_banner_and_timestamp(self):
_csv_path, json_path = export_paths("limited_character", "218216016349") _csv_path, json_path = export_paths("limited_character", "218216016349")