Skip to content

feat(soci): add local CSV member-book previews - #152

Merged
toto04 merged 3 commits into
mainfrom
feat/soci-csv-preview
Nov 23, 2026
Merged

toto04 merged 3 commits into
mainfrom
feat/soci-csv-preview

Conversation

@BIA3IA

@BIA3IA BIA3IA commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Adds a local-only Libro Soci CSV preview with explicit column, delimiter, date and source-scope mappings. It reuses the Soci validators, blocks duplicate numbers and conflicting active admissions, and preserves historical admissions and unreviewed fee evidence without guessing account links or payments.

The command does not load configured services, contact the database/Microsoft 365 or send mail. Every candidate remains unresolved pending later local snapshot reconciliation. Console output contains only counts and coded diagnostics; an optional detailed plaintext report is created exclusively with private permissions outside Git worktrees. Includes synthetic examples and operator documentation. No apply option, schema change or new dependency.

Targets main directly. It was first stacked on #151, but it uses nothing from the lifecycle work: its only Soci imports (END_REASONS, memberNumberSchema, optionalDetailsSchema) are already on main. The dashboard documentation for this command moved to its own admin PR.

Validation: 481 tests passed, 17 skipped, including 32 new parser/preview/CLI tests; typecheck, full Biome check and production build passed. Coverage includes quoted/multiline CSV, dates and tax codes, duplicates, financial non-inference, redacted errors, bounded inputs, and private/non-overwriting outputs. The full test suite passed when run separately from other heavyweight checks; an earlier simultaneous run hit the existing Secret Santa mailer test's 5-second timeout. No timeout or test assertion was changed. Optional database suites were not enabled. No real books, production reads, writes or deployment were involved.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: PoliNetworkOrg/backend
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 7e167a3
  • Layers: Repository YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: daace367-5c28-4753-8c95-e873800fc966
Commits

Reviewing files that changed from the base of the PR and between 21a027e and cadbe6d.

Files ignored due to path filters: 1

  • scripts/examples/soci-import.synthetic.csv is excluded by !**/*.csv
Files selected for processing: 8

  • README.md
  • package.json
  • scripts/examples/soci-import.mapping.json
  • scripts/soci-import-preview.ts
  • src/soci/import-csv.ts
  • src/soci/import-preview.ts
  • tests/soci-import-cli.test.ts
  • tests/soci-import.test.ts

Walkthrough

Adds a local SOCI CSV preview pipeline. The pipeline validates mappings, parses CSV records, and reports normalized candidates, diagnostics, and row counts. The CLI supports optional private report output and does not perform reconciliation or application.

Changes

SOCI CSV preview

Layer / File(s) Summary
CSV parsing and records
src/soci/import-csv.ts, tests/soci-import.test.ts
Adds CSV record and error types, parsing for comma- and semicolon-delimited input, and limits for cells, columns, and records. Tests cover quoting, line endings, blank records, and malformed or oversized input.
Mapping and preview normalization
src/soci/import-preview.ts, tests/soci-import.test.ts
Adds mapping and header validation, candidate normalization, row and cross-row diagnostics, and preview status and counts. Tests cover field validation, history scope, duplicates, and unresolved fee and account evidence.
Local CLI and preview reporting
scripts/soci-import-preview.ts, scripts/examples/soci-import.mapping.json, package.json, README.md, tests/soci-import-cli.test.ts
Adds the Bun CLI, bounded UTF-8 input reads, optional exclusive report creation with mode 0600, summary output, and exit codes. Adds an example mapping, invocation documentation, and CLI tests for output handling, errors, and input limits.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as soci-import-preview.ts
  participant Files as Local files
  participant Preview as previewBookCsv
  CLI->>Files: Read mapping and CSV as UTF-8
  CLI->>Preview: Submit CSV text and mapping
  Preview-->>CLI: Return preview rows and counts
  opt Optional report output
    CLI->>Files: Create report exclusively with mode 0600
  end
  CLI-->>Files: Print summary and diagnostics
Loading

Change: Feature

Merge Risk: Minimal · previous review 21a02 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 3

Check name Status Explanation
Title check Passed The title "feat(soci): add local CSV member-book previews" matches the main change: an offline CSV preview command for Libro Soci member-book files. The raw summary covers the new preview script, the …
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.
Full details: Title check

Explanation

The title "feat(soci): add local CSV member-book previews" matches the main change: an offline CSV preview command for Libro Soci member-book files. The raw summary covers the new preview script, the CSV parser, the preview pipeline, and the tests, all of which fit the title. The title is specific and follows a conventional commit style.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@toto04
toto04 force-pushed the feat/soci-csv-preview branch from 52db6b7 to 21a027e Compare November 23, 2026 15:44
@toto04
toto04 changed the base branch from feat/soci-manual-lifecycle to main November 23, 2026 15:44
@toto04

toto04 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Rebased onto main and retargeted from feat/soci-manual-lifecycle to main.

#151 is on hold until the Consiglio Direttivo decides how the automatic lapse should act on its behalf (see the review on #151). This PR doesn't depend on it: it calls none of the lifecycle code, and its only Soci imports (END_REASONS, memberNumberSchema, optionalDetailsSchema from src/soci/contract.ts) are already on main. So it can be reviewed and merged on its own.

  • The rebase is the same single commit (52db6b7 → 21a027e), with the same author and content: 9 files, +793. It applied without conflicts.
  • On the rebased tree, the 26 parser and preview tests pass, Biome is clean on the changed files, and the command runs offline on the synthetic example.
  • The 6 tests in tests/soci-import-cli.test.ts failed on my machine both before and after the rebase. They run bun with an empty environment in a temporary folder, so the failure looks local; CI will confirm.
  • The dashboard documentation for this command (docs/people/soci-import.md) moved out of feat(soci): add lifecycle actions and pending deletion admin#169, which is blocked by feat(soci): complete membership lifecycle and account deletion #151, into a separate admin PR.

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

Additional comments: 1

tests/soci-import-cli.test.ts-67-67: 1

67-67: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Guard the permission-bit assertion to POSIX platforms.

On Windows, a file written with mode 0o600 reports a different mode, usually 0o666. This assertion then fails even when the command works. Run the check only when process.platform !== "win32", and keep a file-existence check on Windows.

Proposed fix

-    expect((await stat(path)).mode & 0o777).toBe(0o600)
+    const mode = (await stat(path)).mode & 0o777
+    if (process.platform !== "win32") expect(mode).toBe(0o600)

Based on learnings, exact POSIX permission bits must not be asserted on Windows.

Source: Learnings

Review info

Run configuration

  • Source mode: Auto
  • Repository: PoliNetworkOrg/backend
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: ab6530e
  • Layers: Repository YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3eab23d2-2c04-45f9-8f01-9440cb2986e7
Commits

Reviewing files that changed from the base of the PR and between ab6530e and 21a027e.

Files ignored due to path filters: 1

  • scripts/examples/soci-import.synthetic.csv is excluded by !**/*.csv
Files selected for processing: 8

  • README.md
  • package.json
  • scripts/examples/soci-import.mapping.json
  • scripts/soci-import-preview.ts
  • src/soci/import-csv.ts
  • src/soci/import-preview.ts
  • tests/soci-import-cli.test.ts
  • tests/soci-import.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

BIA3IA added a commit to PoliNetworkOrg/admin that referenced this pull request Nov 23, 2026
* docs(soci): plan local member-book import preview

* docs(soci): document local CSV preview and reconciliation scope

* docs(people): point the import preview docs at backend #152

The CSV preview is in review in PoliNetworkOrg/backend#152, which targets main on its own. List soci-import.md in the People docs index.

---------

Co-authored-by: Bianca <ianoselbiancaroberta02@gmail.com>
- List errors before warnings on the console and count the warnings every
  row carries, so blocked rows late in a long book are named without --out.
- Block admissions sharing a tax code that were in force at the same time
  (overlapping_admissions), not only multiple active ones.
- Delete a partially written report when writing fails, and report
  output_partial if it cannot be removed.
- Skip lines of only spaces or tabs as blank lines.
- Refuse endReasonValues keys with leading or trailing spaces.
- Count the per-cell limit in characters rather than UTF-16 units.
- Give the CLI tests a 60 s timeout, since each test spawns Bun several times.
- Document which blocked rows keep their candidate.
@toto04
toto04 merged commit 861618f into main Nov 23, 2026
2 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