CRA data rules and filing specs
See how the CRA Error Code List is compiled into checks, how filing specifications and adapters build .COR and AT1 files, and what is unverified.
TaxPilot builds the electronic files a return would be filed with, and runs CRA's own data rules against them, so a preparer sees CRA rejections before filing. It never transmits anything. The files are previews, filing happens in certified software or Represent a Client, and the filing is then recorded in TaxPilot.
The .COR layout (src/efile/cor-format.json) and the AT1 layout (src/efile/at1-format.json) are both unverified, so every filing spec is unverified and transmittable is always false. The 2026 CRA data rules were extracted from a commercial product, not from CRA. There is no Revenu Québec adapter.
CRA data rules
A CraRuleSet (src/efile/cra-rules.ts) is { release, source: { title, file, sha256 }, rules }. The 2026 set (src/rules/cra/2026.json, release 2026-10) has 678 rules. The 2020 to 2025 sets hold one manual notice each: no CRA Error Code List is on file for those years.
pnpm --filter @workspace/t2 cra-rules runs scripts/build-cra-rules.ts, which compiles each rule's wording with compileRule into one of these kinds:
checkCraRules runs them against the e-file data set, keyed by CRA's schedule and line codes. Every rule gets one outcome: passed, failed, not-filed (the schedule isn't part of this return), unsupported (the rule names a line TaxPilot doesn't report) or manual. Nothing passes silently.
The source list has extraction artifacts: merged codes, repeated codes and run-together words. It must be re-sourced from CRA before certification.
Filing specifications
export type FilingSpec = {
id: string
label: string
status: "verified" | "unverified" | "test-only" | "retired"
cor: CorFormat
craRules: CraRuleSet
/** Field id → its e-file line where it differs from the printed line; null = not filed under this spec. */
lines?: Record<string, string | null>
}Each release lists its specs in filingSpecs: cor-2020 to cor-2026, all unverified. generateCor(reg, ev, spec) returns a CorResult with the text and bytes, the lines and schedules, diagnostics, every CRA rule outcome, layoutStatus, specId and transmittable, which is true only when the file is ok and the spec is verified. assertTransmittable refuses a spec that isn't verified or isn't listed for the return's release.
In the repository, buildCor(formSetId, ev) and buildAt1(formSetId, ev) build with the release's spec, and filingSpecFor(formSetId) picks the first spec that isn't retired. At approval the .COR text is built and stored on the locked version as payload, so the file a user downloads later is exactly what was approved.
Filing adapters
export type Authority = "CRA" | "AB-TRA" | "RQ"
export const FILING_ADAPTERS: FilingAdapter[] = [CRA_T2_2026, AB_AT1_2026]
export const adaptersFor = (authority: Authority) =>
FILING_ADAPTERS.filter((a) => a.authority === authority && a.status !== "retired")CRA_T2_2026builds the T2 .COR withCOR_2026.AB_AT1_2026builds the Alberta AT1 Net File XML withgenerateAt1andAT1_2026(src/efile/at1.ts). The app labels it Preview · not TRA-certified.RQhas no adapter. The CO-17 and its schedules are calculated and printed only.
Filing obligations
filingObligations(corp, ev?) in src/filing-obligations.ts lists the returns a corporation must file: always the T2, plus the AT1 or CO-17 when the profile lists Alberta or Québec, or Schedule 5 records a permanent establishment there (s5.019, s5.011). Each FilingObligation has authority, form, jurisdiction, title, supported (an adapter exists for the authority) and a reason shown to the user. Where tax is calculated is separate: provincial tax carried on the T2 is still calculated.
The filing gate
filingGate(state, ret) in src/repo.ts checks the latest locked version, and recordFiling refuses while it blocks. Nothing overrides it.
Add a filing specification
- Get the authority's published specification.For CRA, the Corporation Internet Filing specifications; for Alberta, TRA's Net File developer specification and XSD.
- Add the format and rules.Put the layout in a format JSON and the compiled rules in
src/rules/cra/<year>.json. Uselinesfor any field whose e-file line differs from the printed line. - Declare the spec in
src/efile/specs.tsand list it in the release'sfilingSpecs.Mark itverifiedonly once it has been checked against the published specification. Atest-onlyspec never ships. - Test with fixtures.
test/efile.test.tsandtest/at1-efile.test.tsare the starting points.test/at1-reference.test.tslists known AT1 gaps.
Still to validate with CRA before any transmission work: the .COR layout, that CRA accepts the exact stored bytes, the format of confirmation numbers and acknowledgments, and how an adjustment must be submitted. The background is in docs/futuretax-analysis/06-cor-generator.md and docs/rules-engine.md.
Related
- Rules releasesLearn what a rules release contains, how a return picks one, how releases are published and frozen, and how returns move between them.
- Taking in ITA amendmentsDetect a change to the Income Tax Act, a provincial statute or a CRA form, and ship it safely as a new rules release.
- State, actions and permissionsRead and write firm data through the repository and store, check permissions with can(), and keep the audit trail and undo working.