the life cycle of a target and the long tail · lesson 4 of 9 · sources checked 2026-11-22
the adapter contract and templates by target class
This lesson defines the interface that each site adapter implements, and one template that serves all targets of one class.
purpose
When the code for each site has its own form, each new site costs as much as the first one. A site adapter contract and an extractor template give the code of many sites the same shape. Then a new site costs a data row and a test, not a new program.
objectives
- Name the five parts of a site adapter contract.
- Write a closed status list with one action for each status.
- Write one template for one target class, and fill it with the data of two lab targets.
- Explain why a new failure must not fall into a silent default.
new terms
- site adapter contract
- The interface that the code for each target implements: flows, extraction, oracle, data contract, and status.
- extractor template
- The shared code of one target class that the data for each target of the class fills.
- long tail
- The many targets that each give a small share of the work but together hold most of the fixed cost.
how it works
A site adapter is the code for one target. With ten targets, each adapter can have its own form. With hundreds of targets, the long tail sets the cost: many small targets, and each one must get a fix when its page changes. A fix is fast only when each adapter has the same shape.
the five parts of the contract
The site adapter contract is the interface that each adapter implements. It has five parts:
| part | what it holds | question that it answers |
|---|---|---|
| Flows | The declared steps on the target, each a flow | Which pages does the adapter read, and in which order? |
| Extraction | The selectors and the field map | How does a page become records? |
| Oracle | The success oracle of the target | Are the records the real content? |
| Data contract | The data contract of the records | Which fields and types does each reader get? |
| Status list | A closed list of status values | What occurred, in one word? |
For example, an adapter for a list of jobs has one flow: read the list page. Its extraction reads a title and a place from each row. Its oracle says that each record must have both fields.
the closed status list
The status list is closed: the adapter can return only a value of the list. Each value has one action. The operator writes the list one time, for all adapters:
ok: deliver the records.no-records: the main part of the page is empty. Deliver an empty set.form-changed: the main part of the page has content, but the selectors find no rows. Open a repair proposal.oracle-fail: the records do not pass the oracle. Hold the records, and open a repair proposal.refused: the site refused the request. Stop the target, and send it to review.unclassified: no other value is true. Hold the records, and send the target to review.
The last value is the important one. Without it, a new kind of failure falls into a default. A default of ok delivers bad records with no alarm. A default of no-records hides a changed page as an empty page. With unclassified, each new failure stops at a person.
For example, a redirect to a login page matches no other value, thus it gets unclassified. The target then waits for a person, and no record goes to a reader.
The action for refused never changes the request to pass the refusal. The output is a stop and a review. The review decides about a slower pace, a volume cap, the declared path, or the end of the target.
the template of a class
A target class is a group of sites with the same kind of content, for example lists of jobs. The sites of one class differ in small parts: the selectors, the field names, and the pace. They do not differ in the flows, the oracle, or the data contract.
An extractor template is the shared code of one class. The data for each target fills it. For example, target jobs-a puts each job in a list item, and target jobs-b puts each job in a table row. The template is the same for both. Only two rows of data differ.
Keep each difference of a target as data, not as a new branch of code. A data row is easy to read, to test, and to compare with the rows of other targets. A target that does not fit the data row must have a rule of its own. The place of such a rule is in The override layer.
why target 500 costs less than target 50
Without a contract, target 50 must have its own program, its own tests, and its own failure words. With a contract and a template, target 500 must have one data row, one oracle test, and one canary. The fixed cost moves into the template, and the template pays it one time for the class.
The contract also makes the work of a person faster. A person who knows one adapter of a class can read each adapter of that class.
the two sides
| automation side | detection side |
|---|---|
| A contract and a template make a new target cheap. The closed status list keeps a new failure out of a silent default, and a refusal goes to a stop and a review. | One template behaves the same on each site of a class. A defender that protects many sites of one class can link those sites by that common behavior. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| Free form code for each target | No design work before the first target | Each fix starts from zero, and each adapter has its own failure words. | For a few targets with no plan to grow |
| A contract with no template | One shape and one status list for all adapters | Each target still has its own extraction code. | When the targets of a class differ in their flows |
| A contract and a template for each class | A new target is a data row and a test. | One change of the template touches each target of the class. | For many targets of one class |
| An open status list | A new status costs no change of the list. | A new failure can fall into a default with no alarm. | Never as the only status rule |
A closed list with unclassified | Each new failure stops at a person. | A person must examine each unclassified result. | For each adapter |
diagram
the site adapter contract, with the template of a class above it
- Template of a target classShared code for each target of one class. The data for each target fills it.
- FlowsThe declared steps that the adapter runs on the target.
- ExtractionThe selectors and the field map that make records from a page.
- OracleThe rule that decides if the records are the real content.
- Data contractThe fields, the types, and the schema version that each reader gets.
- Closed status listOne fixed status for each result, and one action for each status.
code example
The example uses synthetic targets and synthetic pages. No code sends a request. The template of the class "job listing" gets the data of two targets, and five synthetic pages go through it.
A site adapter interface with a closed status list, and one template for one target class with data for each target.
// Site adapter contract, closed status list, and one class template. Synthetic data.
type Status = "ok" | "no-records" | "form-changed" | "oracle-fail" | "refused" | "unclassified";
const ACTION: Record<Status, string> = {
"ok": "deliver the records",
"no-records": "deliver an empty set",
"form-changed": "open a repair proposal",
"oracle-fail": "hold the records, open a repair proposal",
"refused": "stop the target, send it to review",
"unclassified": "hold the records, send the target to review",
};
type Job = { title: string; place: string };
interface SiteAdapter {
target: string;
flows: string[];
extract(page: string): Job[];
oracle(records: Job[]): boolean;
run(page: string, httpStatus: number): { status: Status; records: Job[] };
}
// The data for each target. The differences between targets stay here.
type TargetData = { target: string; row: string; title: string; place: string };
const inside = (text: string, tag: string): string =>
text.split(`<${tag}>`)[1]?.split(`</${tag}>`)[0]?.trim() ?? "";
// The template of the class: shared code, filled by the data of one target.
function jobListingTemplate(d: TargetData): SiteAdapter {
return {
target: d.target,
flows: ["list-page"],
extract: (page) => page.split(`<${d.row}>`).slice(1)
.map((r) => ({ title: inside(r, d.title), place: inside(r, d.place) })),
oracle: (records) => records.every((r) => r.title !== "" && r.place !== ""),
run(page, httpStatus) {
if (httpStatus === 403 || httpStatus === 429) return { status: "refused", records: [] };
if (httpStatus !== 200) return { status: "unclassified", records: [] };
if (!page.includes(`<${d.row}>`)) return { status: page.includes("<main></main>") ? "no-records" : "form-changed", records: [] };
const records = this.extract(page);
return { status: this.oracle(records) ? "ok" : "oracle-fail", records };
},
};
}
const targets: TargetData[] = [
{ target: "jobs-a", row: "li", title: "h3", place: "em" },
{ target: "jobs-b", row: "tr", title: "b", place: "i" },
];
const pages: [number, string, number][] = [
[0, "<main><li><h3>Welder</h3><em>Town A</em></li><li><h3>Cook</h3><em>Town B</em></li></main>", 200],
[1, "<main><tr><b>Driver</b><i>Town C</i></tr></main>", 200],
[1, "<main><div>new form</div></main>", 200],
[0, "<main><li><h3>Nurse</h3></li></main>", 200],
[0, "", 429],
];
for (const [i, page, code] of pages) {
const a = jobListingTemplate(targets[i]);
const r = a.run(page, code);
console.log(`${a.target}: ${r.status}, records: ${r.records.length}, action: ${ACTION[r.status]}`);
}output
One line for each synthetic page: the target, the status, the count of records, and the action.
jobs-a: ok, records: 2, action: deliver the records
jobs-b: ok, records: 1, action: deliver the records
jobs-b: form-changed, records: 0, action: open a repair proposal
jobs-a: oracle-fail, records: 1, action: hold the records, open a repair proposal
jobs-a: refused, records: 0, action: stop the target, send it to reviewThe output shows that one template serves two targets with different page forms. A changed page, a record with no place, and a refusal each get their own status and their own action.
failure modes
| problem | cause | correction |
|---|---|---|
| A changed page delivers bad records with no alarm. | The status list has a default of ok. | Use a closed list with unclassified, and send that value to a person. |
| A changed page looks like an empty page. | The adapter returns no-records when the selectors find nothing. | Separate form-changed from no-records with a check of the main part of the page. |
| A fix of one target breaks other targets of the class. | The fix went into the template, not into the data row of the target. | Put the difference of the target in its data row. Test the template on each target of the class. |
| Each adapter uses its own failure words. | The adapters have no contract. | Write one contract and one status list for all adapters. |
| A refused target gets more requests. | The action for refused sends the request again. | Make the action a stop and a review. |
check questions
Name the five parts of a site adapter contract.
sample answer
Flows, extraction, the oracle, the data contract, and the closed status list.
An adapter gets a page with the HTTP status 503. No rule of the adapter covers this status. Which status must the adapter return?
- ok
- no-records
- unclassified
- form-changed
answer
c. unclassified
No other value of the closed list is true. Thus the status is unclassified, and the target goes to a person.
What is the action for the status refused?
- Stop the target and send it to review.
- Send the request again at once.
- Deliver an empty set.
answer
a. Stop the target and send it to review.
A refusal goes to a stop and a review. The review decides about a slower pace, a volume cap, the declared path, or the end of the target.
Two targets of one class put each job in a different element. Where does this difference go?
- Into a new branch of the template code
- Into the data row of each target
- Into the data contract
answer
b. Into the data row of each target
The template is the shared code of the class. Each difference of a target stays as data in the data row of that target.
Explain why a new kind of failure must not fall into a default status.
sample answer
A default of ok delivers bad records with no alarm. A default of no-records hides a changed page as an empty page. With the value unclassified, each new failure stops at a person.
exercise
exercise Do this task on paper or in your own lab, with synthetic data. Do not send a request to a site. Use these inputs:
- Target class: "event listing". Each record has a name, a date, and a place.
- Target
events-a: each event is a list item. The name is a level-3 heading, the date is atimeelement, and the place is anemelement. - Target
events-b: each event is a table row. The name is abelement, the date is atimeelement, and the place is anielement.
- Write the oracle rule of the class.
- Write the data row of each target.
- Write the status of a page of
events-bwith rows but notimeelement. - Write the status of a page of
events-awith the HTTP status 503.
sample answer
The answer uses the template of the code example, with one more field.
The oracle rule: each record has a name, a date, and a place. The data row of events-a is: row li, name h3, date time, place em. The data row of events-b is: row tr, name b, date time, place i.
A page of events-b with rows but no time element gives records with no date. The records do not pass the oracle, thus the status is oracle-fail. A page with the HTTP status 503 is not in a rule of the template. Thus the status is unclassified, and the target goes to a person.
sources
- My model of the site adapter contract, the closed status list, and the template of a target class, 2026-11 (not public).