# C-DATA FD1601S-B1 Auto SN parser plan

## Current contract

`GET /api/olt-devices/{olt_device_id}/auto-sn?pon_port=1/1/1` is a UI/API placeholder. It validates an active registered OLT, the exact `C-DATA` / `FD1601S-B1` profile, and a bounded PON token. It then returns **503** with `available: false` and an empty `results` array. The implementation imports no transport library and constructs no command.

The add-customer UI exposes GPON/PON + a result dropdown only for that registered model. Selecting a future result will only copy its serial number into the form; it cannot configure, register, or provision an ONU.

## Preconditions to enable discovery

1. Obtain the FD1601S-B1 firmware/version-specific, vendor-confirmed **read-only** command grammar for listing unregistered ONTs on one PON. Record source, firmware, privilege level, and a redacted transcript.
2. Review the command and transport separately: allow one fixed command template only; reject shell metacharacters; use a read-only account; set connect/read timeouts; avoid pagination/state-changing commands.
3. Create a dedicated adapter that accepts only the normalized `N/N/N` PON value, uses no dynamic CLI fragments beyond those numeric segments, and returns typed `AutoSnResult(serial_number, brand, port)` records.
4. Keep configuration/provisioning adapters separate. Discovery success must never register an ONU, allocate an ONU ID, or send provisioning commands.

## Parser fixtures and tests

Add sanitized raw CLI fixtures from the verified firmware under `tests/fixtures/cdata_fd1601s/` for: one ONT, several ONTs, no ONTs, pagination/banner noise, malformed rows, and a different-PON row. Parser tests must assert:

- output is parsed into stable typed records and deduplicated by serial number;
- only records for the requested normalized PON are returned;
- no rows, malformed output, or an unexpected prompt returns an explicit parse error or empty list according to the verified grammar—not fabricated results;
- serial values preserve the device-reported token after strict character/length validation;
- no adapter call occurs until the feature flag/grammar state changes from `grammar_unverified` to `ready`.

Add endpoint tests for 422 invalid PON input, 404 inactive/missing OLT, 409 wrong profile/model, 503 grammar-unverified state, and the eventual successful JSON shape. Integration tests must replace the transport with a fake and assert the adapter sends exactly the reviewed read-only command once; no provisioning API may be reachable from this endpoint.
