# Test discovery and authorized access

Start with the [entrypoint](README.md), [data-bank contract](data-bank.md),
[source integrations](integrations.md), and [SOP interfaces](sops.md). This guide
adds checks, not new interfaces. Reports has no business-data query API.

| Surface | Authentication | A successful check proves |
| --- | --- | --- |
| Public Reports catalog and guides | None | Discovery files are reachable and structurally usable; not source health or dataset access |
| Public SOP JSON | None | The documented public procedure interface responds; not measured work |
| Source reporting APIs | Source-owned user/service scope | Only the tested credential, route and date window work; not farm-wide access |
| Private dataset CLI | Authorized private checkout and captures | Local contracts/releases can be inspected and verified; not current upstream completeness |
| Private Sales bundle | File reader permission plus Google OAuth supporting Drive downloads | Only actual complete-byte download and trusted hash/schema validation prove retrieval; Sheets access alone does not |

## Bounded read-only checks

Run from a private working directory. Disable shell tracing. Never print
credentials, authorization headers, response bodies, private records or command
output containing business totals. Keep any captures and detailed receipts outside
Reports and its public `docs/`. Do not follow an authenticated redirect to another
host. Use normal owner-provisioned credentials; do not paste secrets into chat.

The following Python check uses only the standard library, at most three requests,
a 15-second timeout per request and a 2 MiB response limit. It prints only status
and validation outcome. No authentication is needed. Expected: HTTP 200, a
version-1 catalog with Sales discovery fields, a Markdown entrypoint, and JSON
from the documented public SOP list. An empty SOP list is not an access failure.

```sh
python3 - <<'PY'
import json
from urllib.request import urlopen
from urllib.error import HTTPError, URLError
checks = [
    ('catalog', 'https://reports.deckfamilyfarm.com/catalog.json'),
    ('entrypoint', 'https://reports.deckfamilyfarm.com/agents/README.md'),
    ('sop-list', 'https://sops.deckfamilyfarm.com/api/public/workflows?enterprise=Sales'),
]
for name, url in checks:
    try:
        with urlopen(url, timeout=15) as r:
            body = r.read(2 * 1024 * 1024 + 1)
            assert r.status == 200 and len(body) <= 2 * 1024 * 1024
            if name == 'catalog':
                c = json.loads(body)
                assert c['schemaVersion'] == 1 and c['agentGuide']
                assert any(x['id'] == 'sales' and x['workbookUrl'] for x in c['recipes'])
                assert c['dataBank']['access'] == 'private_local'
            elif name == 'entrypoint':
                assert 'private data bank' in body.decode().lower()
            else:
                assert isinstance(json.loads(body), (list, dict))
        print(name, '200 content check passed')
    except HTTPError as e:
        print(name, 'HTTP', e.code)
    except (URLError, TimeoutError, ValueError, KeyError, AssertionError):
        print(name, 'transport/content check failed')
PY
```

This SOP check validates JSON transport only; inspect the private receipt against
the documented list/detail contract before asserting procedure coverage. Fetch a
detail only using an ID actually returned by the list, as described in the SOP
guide. Do not guess IDs or enumerate endpoints.

For a source API check, the deployment owner must first provision a private curl
config at `$TIMESHEETS_READ_CONFIG` containing only the documented Poultry service
authorization header. Do not put the token on the command line or enable verbose
output. This optional check is bounded to one day and discards all records:

```sh
curl --config "${TIMESHEETS_READ_CONFIG:?private curl config required}" \
  --silent --max-time 20 --max-filesize 2097152 \
  --output /dev/null --write-out 'poultry-report HTTP %{http_code}\n' \
  'https://timesheets.deckfamilyfarm.com/api/integrations/poultry/labor-report?startDate=2026-09-07&endDate=2026-09-07'
```

Expected: HTTP 200 for an authorized deployment, with the daily/task labor JSON
contract in [integrations](integrations.md). Status alone proves route access,
not JSON schema, meaningful rows, Sales coverage or paid wages. Validate content
privately against the source-owned contract before using it. This service scope
does not replace a reporting credential for other enterprises. Do not invoke
launch/callback endpoints or an operational bootstrap as a reporting test.

For local checks, set `FARM_DATA_ROOT` to the authorized private checkout and run
the existing CLI. Each invocation below has a 60-second bound and suppresses
business output; exit 0 is expected. Exit 124 means timeout, not missing data.

```sh
cd "${FARM_DATA_ROOT:?authorized checkout required}"
timeout 60s python3 scripts/data_bank.py list >/dev/null 2>&1; echo "list exit=$?"
timeout 60s python3 scripts/data_bank.py describe square.market_events >/dev/null 2>&1; echo "describe exit=$?"
timeout 60s python3 scripts/data_bank.py verify --manifest "${RELEASE_MANIFEST:?pinned manifest required}" >/dev/null 2>&1; echo "verify exit=$?"
```

`list`/`describe` prove CLI/definition availability, not released rows. Resolve
`RELEASE_MANIFEST` from the private runtime catalog, never by file mtime. A passing
`verify` establishes the selected release's integrity under the documented checks;
inspect its requested range, dataset status, schema, gaps and source-as-of dates
privately before claiming the requested coverage. These commands do not collect
or build data. GNU `timeout` is required for these examples.

## Private Sales bundle remote acceptance

Discover `dataBank.salesBundle` in the catalog and follow its
[download and interpretation contract](sales-bundle.md). Current evidence is
`configured`: the private file is provisioned. Actual connected Drive raw download,
trusted SHA-256 verification and source-owned validation passed on November 10,
2026. An anonymous request to the actual Drive media endpoint was denied with
HTTP 403. Denial to a valid ungranted Google identity is **untested**; full remote
acceptance remains incomplete. Do not request a token in chat. Ask for the uploaded
link only when needed; file IDs and trusted expected hashes belong in a private handoff.

| Check through the actual interface | Required evidence |
| --- | --- |
| Authorized intended identity | HTTP 200 / complete original bytes from Drive `GET /drive/v3/files/{file_id}?alt=media`, matching independently trusted SHA-256, supported source-owned schema, pinned release/period and provenance |
| Unauthenticated request | Same file and media interface denies access (401/403/404), no successful media response; no auth headers, cookies or default curl config |
| Valid Google identity without a reader grant | Same interface denies access (403/404) using valid OAuth supporting Drive downloads; no sharing changes. An expired token/401 alone does not test file permission denial |
| Private interpretation | Three complete weeks starting September 7, 14 and 21, 2026 in America/Los_Angeles; exact cents/original pilot integer strings, source/account/location subtotals, normalized events and provenance, hashes/timestamps and all unknown/partial/refund/classification states retained; two unresolved Sales workbook differences remain visible |

Use metadata only to ground the ordinary binary file, not to claim byte access.
The connected Drive `fetch` advertises `download_raw_file=True` and
`include_base64=False` for a raw authenticated file reference; materialization,
byte hashing and content validation must actually succeed. Readable text or a
Sheets read is insufficient. A metadata search, including an empty exact-name
search, is discovery evidence only, not an authorized-download or
unauthorized-denial test.

For a direct denial check the owner can provision a private curl config containing
only the same media URL (anonymous case), or that URL and the ungranted identity's
authorization header (authenticated denial case). Keep both outside Reports.
Disable tracing; do not enable verbose/debug logs. Run separately for each case:

```sh
curl --disable --config "${SALES_BUNDLE_DENIAL_CONFIG:?private test config required}" \
  --proto '=https' --silent --max-time 20 --max-filesize 52428800 \
  --output /dev/null --write-out 'bundle denial HTTP %{http_code}\n'
```

Do not follow redirects. A 200 is a failed denial test even if content seems
empty. A redirect, timeout, missing test identity, invalid credential or connector
inability to issue the negative request leaves acceptance incomplete. Do not
revoke the real reader, broaden access, enumerate other files or create a public
copy for testing. If a connector hides HTTP status, require an explicit access
denial for the same target; a generic tool failure proves nothing. Use the actual
REST interface in an authorized private runtime if the connector cannot support
the negative tests.

The authorized byte/hash example is in the bundle guide. After it passes, validate
schema, release `20260907-20260927-29aba3d42a411b8a`, September 7–27 inclusive,
timezone, source timestamps and comparison evidence using `master_planning`'s
validator/contract. Record the actual validator revision/invocation privately;
Reports does not duplicate its schema or aggregation logic. Fail closed on hash,
schema or metadata mismatch. Preserve source-scoped identities: there is no
verified dated venue mapping in this selected export, and workbook market labels
are not verified Square locations. Known subtotals need not be complete totals;
missing data is not zero. Never add payments to sales or fill gaps from workbook
values. Compare exported subtotals using the shared source-owned calculation,
without forcing reconciliation differences to disappear.

Record UTC time, tested identity/scope (no secrets), method/interface, safe private
target reference, expected/actual statuses, integrity/content outcomes and skipped
checks in a private receipt. `configured` requires actual private upload and reader
provisioning evidence. `remotely_verified` requires all remote checks above to pass;
record `unavailable` for an observed absent/revoked/inaccessible file with the
reason. Local unit tests, synthetic hash checks and prior source reviews cannot
advance remote acceptance. Never publish a receipt containing business data,
file IDs, hashes, tokens or private configuration.

## Local Reports documentation checks

Run these in this checkout, without private records or sibling repositories:

```sh
python3 -m unittest discover -s tests -v
python3 scripts/publish_catalog.py --check
git diff --check
```

The unit tests cover catalog/schema boundaries, discovery links and synthetic
integrity success/failure cases in the documented hash verifier. The publisher
checks safe catalog structure and generated-file freshness. These are local
checks only. Optional `--source-root` checks require separately authorized source
checkouts and do not establish remote acceptance either.

## Record outcomes accurately

Keep a private discovery/access receipt with UTC test time, interface and method,
safe URL/path identifier, requested range, expected versus actual status/content,
credential scope (never its value), exit code, release/schema/hash references and
what remains untested. Separate skipped, blocked and passed checks. Redact private
identifiers from any public summary. Passing a local test is not deployed proof.

- **401/403:** record unauthenticated versus insufficient scope, without response
  records. Ask the owner to provision access privately; do not bypass permissions.
- **404/missing resource:** report the discovered link and timestamp; distinguish
  unavailable catalog links, retired SOPs and absent private files. Do not invent
  replacements or interpret absence as zero activity.
- **Stale captures:** report extraction/source-as-of dates and requested coverage.
  Label historical results; propose an explicit read-only collection and rebuild.
- **Unavailable/partial dataset:** retain status, gaps and affected metrics as
  unknown or blocked. Adapter availability is not release availability.
- **Schema/hash mismatch:** stop affected calculations, record expected/observed
  version or field names privately, and re-review the consumer/source. Do not edit
  immutable releases, coerce unknown fields, or silently fall back to older data.
- **Timeout/transport failure:** record the bound and failure category. It proves
  neither authorization failure nor empty business data.

For the discovery-to-dashboard completion test, use the
[Sales pilot recipe](recipes/sales-pilot.md).
