Delphi-RAG-Lint

drag-lint help

Lookup layer SDK (interface, fake, conformance suite)

Since: 1.63.0-alpha

The tier-3 lookup layer interface for Pascal clients, an in-memory fake for tests, and a conformance suite LC01-LC11 any implementation can run.

Read this when you implement or test the tier-3 lookup layer (fieldrepo.lookup.tier = 3) outside the ORM3 golden: sdk\pascal\lookup\DLLookupLayerIntf.pas is the interface the generated wiring calls, DLLookupLayerFake.pas a TFDMemTable-backed fake, and DLLookupLayerConformance.pas runs LC01-LC11 (7 required, 4 recommended) against any implementation.

Details

sdk\pascal\lookup\ holds what a team needs to write its OWN tier-3 lookup layer (REST, DataSnap, RemObjects, ...) and prove it behaves like the one drag-lint generates code against. Plain Delphi; no drag-lint unit in any uses.

FileWhat it is
DLLookupLayerIntf.pasThe interface unit repo gen-lookup-layer writes (IDLLookupLayer, DLLookupLayer, SetDLLookupLayer, EDLLookupLayer). Byte for byte the generator's text; the self-test fails if they drift.
DLLookupLayerFake.pasTDLLookupLayerFake: an in-memory implementation (FireDAC TFDMemTable). A source store stands in for the server: DefineTable, AddRow, SourceTable; LookupTable serves a read-only copy, Refresh copies again into the same instance. Use it in your form tests, or read it as the contract in code.
DLLookupLayerConformance.pasRunDLLookupLayerConformance(probe): runs cases LC01-LC11 against any IDLLookupLayer and returns one record per case. No test framework needed.
tests\DLLookupLayerConformanceTests.dpr + run_lookup_conformance_selftest.ps1The SDK's own self-test: registration checks, the suite against the fake (strict), and one broken layer per case that must make that case fail.

Running the suite against your implementation

var
  Probe: TDLLookupConformanceProbe;
  Cases: TArray<TDLConformanceCase>;
  C: TDLConformanceCase;
begin
  Probe.Layer := TMyRestLookupLayer.Create(TestServerUrl);   // talks to a TEST server
  Probe.TableA := 'CUSTOMER';  Probe.RowsA := 3;              // two tables it serves, with their row counts
  Probe.TableB := 'COUNTRY';   Probe.RowsB := 2;
  Probe.UnknownTable := 'NO_SUCH_TABLE';                      // one it cannot serve
  Probe.AddSourceRow := procedure(pTable: string)             // add ONE row on the server side
    begin TestServer.InsertRow(pTable) end;                   // nil = LC07 / LC08 are skipped
  Cases := RunDLLookupLayerConformance(Probe);
  for C in Cases do Writeln(DLConformanceLine(C));
  Halt(DLConformanceFailures(Cases, False));                  // True = count recommended cases too
end;

Run it on test data, never on a live server: the suite adds rows through AddSourceRow (RowsA grows by 2, RowsB by 1), calls Refresh, and calls LookupTable once from a worker thread.

The cases

IdLevelRule
LC01requiredLookupTable(T) returns an OPEN dataset with every row of T
LC02requireda second call for the same table returns the SAME instance
LC03recommendedthe table name is case-insensitive (same instance for customer and CUSTOMER)
LC04requiredanother table gets its own dataset with its own rows
LC05requiredan unknown table raises EDLLookupLayer -- not nil, not an empty dataset, not another exception class
LC06requiredan unknown table raises again on the next call (a failure is not cached)
LC07requiredRefresh(T) shows a source change in the same, still open instance
LC08requiredRefresh('') reloads every loaded table in place
LC09recommendedRefresh of a table never requested is ignored (no raise)
LC10recommendedthe dataset is read-only: CanModify = False, Insert raises
LC11recommendeda call off the main thread raises EDLLookupLayer (the interface says "main thread only")

Required = what the interface unit's own comments state. Recommended = the 1.63 SDK defaults the interface text leaves open; DLConformanceFailures(Cases, True) counts them too. The fake passes all eleven.

"Refresh notification" means the instance stays the same: a TDataSource or a lookup field bound to the dataset sees the new rows without being re-wired, because Refresh reloads INTO the instance LookupTable returned.

Self-test

pwsh sdk\pascal\lookup\tests\run_lookup_conformance_selftest.ps1 -Work <scratch> [-Platforms Win64]

PASS = the interface unit equals the generator's golden, and each build prints 0 failed.

Related: repo gen-lookup-layer, repo lookup-source.


All features | CLI reference | IDE menus