HTMLCSSJAVASCRIPTANGULARINTERVIEW QUESTIONSSQLPYTHONJAVAPHPHOW TOW3.CSSCC++C#BOOTSTRAPREACTNEXTJSMYSQLJQUERYEXCELXMLDJANGONUMPYPANDASNODEJSDSATYPESCRIPTANGULARJSGITPOSTGRESQLMONGODBASPAIRGOKOTLINSWIFTSASSVUEGEN AIAGENTIC AIPROMPT ENGINEERINGDOCKERKUBERNETESSPRINGSPRING BOOTUNIXSCIPYAWSCYBERSECURITYDATA SCIENCEINTRO TO PROGRAMMINGINTRO TO HTML & CSSBASHRUSTTOOLS
AI-Powered Full Stack Tutorial 0/70 lessons ~6 min read Lesson 54“React, Next.js, Node, PostgreSQL, LLMs, RAG, agents, and production AI apps”
Testing LLM Features and Agent Workflows
Lesson 53 will commit a model fixture only after the schema gate says it has no key, no URL, and no email.
Course progress0%
Focus
24 guided sections
Practice signal
Examples included
Career prep
Interview Q&A included
AI-Powered Full Stack Development · Lesson 54 · Full-Stack Security, Testing and Deployment
Lesson Overview
Lesson 53 will commit a model fixture only after the schema gate says it has no key, no URL, and no email. That gate does not know whether {"templateId":"cohort_reminder_v1"} is the string the reminder workflow is allowed to accept, or whether a second string that names billing.refund.create must stop before propose. Those are behavior checks. They are also the checks that go red the day someone "just tries" a live key in CI and the vendor returns a different paragraph.
This lesson scores recorded outputs and recorded traces. The suite function runOfflineSuite has no HTTP client in its arguments. Fixtures live under fixtures/model/ and fixtures/traces/. A case fails if any required check fails. A judge comment, when you add one later, is an extra note. It cannot flip a failed check to pass, which is the same rule as Lesson 18.
The product under test is still TechLearningPro: the cohort reminder from Lesson 47 and a grounded tutor answer in the style of Lesson 18. Tenants are Northwind and Contoso. Learner ids are synthetic. The prompt versions are cohort-reminder-v1 and tutor-answer-v3.
Planning assumptions:
CI of this suite sets nothing named MODEL_API_KEY. A test fails if loadFixture sees apiKey, url, or authorization.
Required checks are deterministic: JSON shape, allow-listed template, absence of tool fields, absence of @ in traces, and modelCalled === false when the reason is nothing_to_send.
The suite does not call the workflow's mail port. It scores the artifacts the workflow already produced in fixtures.
A nightly live run is out of scope. If finance later approves one, it is a different script, a mounted secret, a token budget, and a report that cannot promote a release by itself.
Fixtures use public lesson wording and team-written questions. They do not use production transcripts.
Learning Objectives
By the end of this lesson you will be able to:
Explain why a live model call is the wrong default for a pull-request test.
Load a fixture only when it has id, promptVersion, and output, and reject secret-shaped keys.
Score a cohort fixture with required checks: exact template, no tool field, no extra keys.
Score a trace fixture for email, secret markers, cross-tenant ids, and spend on an empty cohort.
Score a tutor fixture for support in the excerpt, a forbidden claim, and the abstain sentence.
Fail the case when any required check fails, and keep a judge from overturning that failure.
Pin cohort-reminder-v1 and tutor-answer-v3 so a new prompt is a new file, not a silent edit.
Aggregate a SuiteReport with pass count, fail count, and { id, check } failures.
Block promotion when failed > 0 or the pass count drops below the baseline.
Assert the suite module never receives a fetch implementation.
Keep learner names and inboxes out of the golden tutor cases.
Separate "the fixture is safe" (Lesson 53) from "the fixture behaves" (this lesson).
Name the checks you will not claim: open-ended helpfulness, production latency, and vendor uptime.
Write a regression fixture when a bad model string escapes to staging, using synthetic data.
Point the browser proof of the same pause screen at Lesson 55.
No provider key. The fixtures in this lesson are the model.
What is Testing LLM Features and Agent Workflows?
An LLM feature test in this course is a required check on a string the team stored: a template id, a grounded sentence, an abstain line. An agent workflow test is a required check on a trace the workflow stored: reason, recipient count, modelCalled, tenant id. The suite runs every case offline and returns a report. The gate blocks promotion when any required check fails.
A fixture is the stored string plus its id and prompt version. A required check is a boolean the team can explain without a second model. A judge is an optional commenter. Lesson 18 already set the rule that a judge does not overturn a failed check. This lesson keeps that rule for workflows.
This is not a claim that the model is "good." It is a claim that the strings you last accepted still satisfy the safety properties of the reminder and the tutor. When you change a prompt, you add a version and you re-score. You do not edit yesterday's fixture in place and call it the same version.
Term
Meaning in this lesson
Fixture
{ id, promptVersion, output } or a trace row
Required check
A named boolean that can fail the case
Suite
runOfflineSuite, no client argument
Gate
block when any required check fails
Baseline
Minimum pass count stored beside the version
Judge
Optional note, never a promotion
Live run
A different, budgeted script this lesson does not include
Why Do We Need It?
text
A prompt change "looks fine" in one manual chat
|
v
The model adds a tool name, a learner id, or a claim the excerpt does not support
|
v
Required checks on committed fixtures, versions pinned
|
v
The gate blocks on the first failed check
|
v
A browser test can later show the pause, still without a live key
Benefits:
The refund tool and the extra learnerIds key fail in CI the same way they fail in Lesson 47's unit tests, using stored strings.
Empty-cohort spend is a trace assertion, so a regression that calls the model for nobody is visible without a bill.
Tutor cases stay on public excerpts, so the eval set does not become a second copy of learner data.
Prompt versions make a behavior change reviewable.
The pull request stays green during a provider outage, because it never dials the provider.
Real World Example
The fixture valid-template is {"templateId":"cohort_reminder_v1"}. The scorer's checks template_exact, no_tool, and no_extra_keys pass. The fixture refund-tool is {"tool":"billing.refund.create","templateId":"cohort_reminder_v1"}. no_tool fails, so the case fails even though the template id is also present. The fixture extra-ids adds learnerIds: ["lrn_contoso"]. no_extra_keys fails. The trace fixture empty-cohort has reason: "nothing_to_send" and modelCalled: false. A trace that says modelCalled: true for that reason fails no_spend_on_empty.
The tutor fixture includes the excerpt "An HNSW index is approximate." The question is "Does the index guarantee the exact nearest neighbor?" The accepted output contains the abstain sentence "The excerpt does not support a guarantee." A cheerful "Yes, it is exact" fails forbidden_claim.
Banks score a scripted advice model on prohibited phrases before anyone funds a live shadow. Hospitals score a discharge summary on whether each drug name appears in the chart excerpt. Amazon-style and Shopify-style shops score a support draft on order-id grounding. Microsoft and Google enterprise copilots keep evaluation sets out of customer content. Netflix-style rankers use offline replay before a live bucket. TechLearningPro's version is the template object, the trace, and the excerpt.
Internal Working
loadFixture accepts an unknown JSON value. It requires id, promptVersion, and output as strings. If the object has apiKey, authorization, url, or headers, it throws fixture_rejected.
promptVersion must be cohort-reminder-v1 or tutor-answer-v3, chosen by the suite name. A mismatch is check version_pin.
For a cohort output, scoreCohort parses JSON. A tool field fails no_tool. Any key other than templateId fails no_extra_keys. A value other than cohort_reminder_v1 fails template_exact. Parse errors fail json_shape.
For a trace, scoreTrace serializes the row. @ fails no_email. The substring TEST_ONLY_MODEL_TOKEN or apiKey fails no_secret. Tenant northwind plus lrn_contoso fails tenant_fence. nothing_to_send with modelCalled: true fails no_spend_on_empty.
For a tutor case, scoreTutor checks that every required support phrase appears, that every forbidden phrase is absent, and that an abstain case contains the abstain sentence. The excerpt is the only source. The check does not call a model to decide.
runOfflineSuite maps cases to failures { id, check }. A case with one failed check is a failed case. There is no partial credit.
gate returns block when failed > 0. It also returns block when passed is below baseline.minPass. Otherwise it returns promote.
promote here means "this offline suite is allowed to be cited." It does not deploy the prompt. Lesson 56's pipeline is what moves bytes.
The function signatures do not include fetch. A reviewer who adds a client parameter is changing the lesson's contract and should expect the "no client" test to fail.
Judge text, if stored, lives on an optional note field that gate ignores.
There is no request flow to a vendor. The response is the report. A human reads the failed check id.
Deep Dive
Required checks versus a judge
template_exact is required because the mail adapter owns one body, cohort_reminder_v1. A fluent paragraph with the right vibe and the wrong id is a failure. no_tool is required because a tool field is how a refund rides along with a valid template. no_extra_keys is required because learnerIds is how a foreign tenant enters the proposal. These checks are boring on purpose. A judge that says "the draft was helpful" does not repair a failed no_tool.
Tutor checks follow Lesson 18. Support phrases must appear. Forbidden phrases must not. Abstain cases must contain the sentence the product shows when the excerpt is silent. A judge may say the tone was cold. Tone is not a required check in this suite. If product later makes tone required, they add a check a person can recompute, or they accept a judge only as a named extra failure after a human sample. They still cannot let the judge erase a grounding failure.
Versions
cohort-reminder-v1 fixtures sit in fixtures/model/cohort-reminder-v1.json. A prompt edit creates cohort-reminder-v2.json and a new expected template id if the template changed. The scorer for v1 stays, because old traces still cite v1. Deleting v1 fixtures on the day you start v2 erases the regression net for any worker still on v1.
tutor-answer-v3 is independent. A reminder change does not move the tutor version. The suite id in the report is the version string, so a dashboard can show which pin blocked.
Traces are part of the agent test
Workflow bugs often hide in the trace, not in the model string. modelCalled: true with nothing_to_send means the orchestrator spent a generation after it knew the cohort was empty. lrn_contoso inside a Northwind trace means the tenant fence leaked into an artifact even if propose was never called. @ means Lesson 52's operational trace was bypassed. Scoring traces keeps the agent test about the system, not only about the paragraph.
The trace fixture omits prompts. A fixture that needs a prompt to make sense is a privacy bug. The id and the reason are enough to name the case.
What "offline" excludes
runOfflineSuite does not sleep, retry, or open a socket. It does not read process.env.MODEL_API_KEY. A wrapper script that checks the env and throws live_model_disabled is a useful belt on the CI job, and the exercise asks for it. The type system is the first belt: there is no client argument to fill in.
Recorded outputs go stale when the prompt changes and nobody records a new string. Staleness is visible because the version pin fails, or because you added a check the old string cannot pass. The fix is a new fixture from a local, budgeted, manual call that a human pastes after removing any personal data. The manual call is not this test. The pasted string becomes the test.
Baseline
baseline.minPass is the number of cases the last reviewed suite passed. For a suite of 6 cases it is 6. Adding a case raises the baseline in the same pull request. Lowering the baseline requires a written reason. gate does not know that reason. The pull request template does.
promote does not mean customers see the prompt. It means the report may be attached to the change. A second control, the feature flag from Lesson 46, still decides whether the reminder runs.
What the suite will not do
It will not sample production transcripts. It will not send mail. It will not approve a ticket. It will not score a screenshot; Lesson 55 owns the panel. It will not average a Likert scale and call the average a pass. It will not drop a required check because the pass rate would otherwise fall below a target.
Code Examples
Place the scorer in packages/eval/src/. Fixtures stay in fixtures/. The scorer imports nothing from a provider SDK.
scoreCohort treats a tool field as a failure even when templateId is correct. That matches the orchestrator, which denies the tool before it reads the template.
The foreign trace in the first assertion of the trace test uses reason tool_denied and does not contain lrn_contoso, so it passes. The leaked trace puts the other tenant's id in reason, which is exactly the kind of sloppy artifact the check exists to catch. An email assertion can be added by setting reason to an address. scoreTrace looks at the whole JSON blob, so the check fires.
The process never reads a provider SDK. gate never inspects a note field, because the report has no note field.
Architecture Diagram
text
fixtures/model/cohort-reminder-v1.json
fixtures/traces/reminder-traces.json
fixtures/tutor/tutor-answer-v3.json
|
v
loadFixture --> fixture_rejected on apiKey, url, headers, @
|
v
scoreCohort | scoreTrace | scoreTutor
|
v
SuiteReport { passed, failed, failures[] }
|
v
gate --> promote | block
|
v
Lesson 56 may attach the report. It may not skip a block.
Version pins:
text
cohort-reminder-v1
tutor-answer-v3
Real-Time Enterprise Example
A pull request that edits the reminder prompt adds fixtures/model/cohort-reminder-v2.json only after a human has reviewed the new strings and stripped anything personal. The v1 suite still runs for the worker that has not migrated. The report is a comment on the pull request: failed: 0 or the list of { id, check }. The deploy job in Lesson 56 refuses to continue when the report says block.
The tutor change "Does HNSW guarantee the neighbor?" keeps the abstain sentence. A draft that answers "Yes" fails forbidden_claim even if a reviewer liked the confidence. Support does not paste Priya's real question into the fixture. They write a new question against the public excerpt.
Challenge: a provider incident makes a product manager ask for a live curl in CI "so we know we're safe," the pass rate is 90% and someone wants the gate at 80%, and a judge model labels the refund tool "probably a joke." The pull request stays on fixtures. The gate stays at zero failed required checks, not at an average. The judge is not in gate. A live curl, if it ever exists, is a capped nightly job whose secret is mounted by the runner and whose output cannot flip this report to promote.
Performance Optimization
The suite is CPU on small strings. Keep fixtures to the sentences and JSON objects you actually check. Do not store full chat histories. A hundred cases should finish in well under a second, which is what makes them safe to run on every push.
Do not parallelize with a worker pool until you have measured a need. Parsing JSON is cheaper than scheduling. If a future embedding check appears, that check is a new suite with a recorded vector fixture, still not a live embedding call, until a separate budget exists.
The cost control is the missing client. A test that "just once" hits a model will be copied. The signature with no client is the performance plan and the spend plan.
Security
Authentication. The suite has no user. It runs in CI as a non-production identity with no secret scope.
Authorization. Fixtures do not include other tenants' content. The trace check fails if they do.
Least privilege. No MODEL_API_KEY on the job. The scorer cannot spend.
Validation.loadFixture rejects credential-like keys and @ in outputs.
Secrets. The negative test uses apiKey: "TEST_ONLY_MODEL_TOKEN" in memory and expects a throw. That object is not written to fixtures/.
Tenant isolation.tenant_fence fails when a Northwind trace names lrn_contoso.
Injection. Outputs are parsed as data or searched as text. They are not evaluated and not rendered as HTML here. Lesson 55 renders the panel with locators, not with innerHTML.
OWASP. The relevant issues are sensitive data in test assets and broken integrity of the release gate. The controls are the loader and gate.
Prompt injection inside a fixture is still scored by the required checks. A fixture whose output says "ignore the excerpt" fails support_phrase or abstain_sentence when those phrases are missing. The suite does not need to "understand" the attack.
Common Mistakes
Calling the live model in the pull request. Symptom: flakes, bills, and a key in CI variables. Cause: a demo script was named suite.test.ts. Fix: runCohortSuite has no client. Keep the live idea in a different script with a budget.
Letting a judge overturn no_tool. Symptom: a refund string passes because a comment said "benign." Cause: gate read the note. Fix: the report has no note, and failed > 0 blocks.
Editing v1 fixtures when the prompt becomes v2. Symptom: history no longer reproduces the incident you fixed. Cause: one file was reused. Fix: add a new version file and keep the old scorer.
Putting a production transcript in the golden set. Symptom: learner text in git. Cause: a bug was copied from the admin tool. Fix: write a question against a public excerpt. Lesson 52's clock does not protect the test repository.
Scoring only the model string. Symptom: empty cohorts start spending and CI stays green. Cause: traces were "just logs." Fix: scoreTrace includes no_spend_on_empty and tenant_fence.
Using pass rate as the only gate. Symptom: one refund case is acceptable because 19 others passed. Cause: the threshold was 90%. Fix: any required-check failure blocks. The baseline is a floor on count, not a license to fail a check.
Recording the curl with the key. Symptom: loadFixture throws, or worse, the throw was removed. Cause: a terminal transcript was saved. Fix: store output only, after a human deletes headers.
Treating promote as a deploy. Symptom: customers see a prompt the flag still disables, or the reverse, a blocked suite is deployed by hand. Cause: the report was confused with the pipeline. Fix: Lesson 56 reads block and stops. The flag remains an independent switch.
Partial credit on extra keys. Symptom: learnerIds merges into the proposal. Cause: the scorer warned and still passed. Fix: no_extra_keys is a failure. The case fails.
Abstain cases that pass on a confident wrong answer. Symptom: "Yes, it is exact" is green. Cause: abstain was false on a case the excerpt cannot support. Fix: set abstain: true and require the sentence.
Sharing one suite across prompt versions. Symptom: a tutor change fails the reminder gate for an unrelated reason, and people start skipping. Cause: one giant file. Fix: runCohortSuite and runTutorSuite report their own version.
Asserting the whole string equals a snapshot including whitespace from a vendor. Symptom: a harmless formatting change blocks, and people weaken the gate. Cause: the check was a full-string compare. Fix: required phrases and the template object. Leave style to a human sample.
Best Practices
Run this suite on every pull request, offline.
Keep loadFixture in front of every scorer.
Reject apiKey, authorization, url, headers, and secret fields.
Reject @ and TEST_ONLY_MODEL_TOKEN inside committed outputs.
Pin cohort-reminder-v1 and tutor-answer-v3 separately.
Fail no_tool even when templateId is also present.
Fail no_extra_keys when learnerIds appears.
Score traces for email, secrets, tenant fence, and empty spend.
Score tutor answers for support phrases, forbidden claims, and the abstain sentence.
Use public excerpts and team-written questions.
Let one failed required check fail the case.
Keep judges out of gate.
Block when failed > 0 or passed < minPass.
Raise minPass in the same change that adds a case.
Add a new fixture file for a new prompt version and keep the old one.
Give the suite function no HTTP client parameter.
Store failures as { id, check }.
Attach the report to the pull request. Do not paste production prompts into the ticket.
Leave mail, approval, and deploy to their own lessons.
Leave panel rendering to Lesson 55.
Reproduce a staging miss with a synthetic fixture, not with a customer transcript.
Describe promote as a citation the pipeline may trust, not as the deploy itself.
When a check becomes noisy, tighten the fixture. Do not delete the check to go green.
Interview Questions & Answers
Beginner
Why not call the model from the test?
The pull request would need a key, the result would change under you, and a vendor outage would block unrelated work. The properties this lesson cares about are already visible in stored strings: template id, tool field, extra keys, trace shape, and grounding phrases.
What is a required check?
A named boolean the team can recompute, such as no_tool or abstain_sentence. If it fails, the case fails. A comment about tone is not a required check unless product writes a check they can recompute.
What does promote mean?
The offline report has zero failed cases and enough passing cases. It does not deploy the service and it does not turn on the reminder flag.
Intermediate
Why does a refund tool fail when the template id is correct?
Lesson 47 denies a tool field before it trusts templateId, because a single JSON object can carry both. The scorer uses the same order of suspicion: no_tool fails the case even if template_exact would have passed on its own.
How do you catch a workflow that calls the model for an empty cohort?
The trace fixture says reason: "nothing_to_send" and modelCalled: true. no_spend_on_empty fails. You do not need a bill from the vendor to see the regression.
How do tutor cases stay grounded?
The excerpt is stored on the case. Required phrases must show up in the output. Forbidden phrases must not. Abstain cases must include "The excerpt does not support a guarantee." The scorer does not ask another model whether the answer "seems right."
Senior
How do you add a case after a bad staging output?
A human copies the model string, deletes addresses, keys, and any learner-specific detail, assigns a new id, and puts it under the current prompt version. The suite should fail on that string until the product code rejects it, or the string should be the new accepted output if the behavior was actually correct. Production transcripts are not the shortcut.
How should a judge be added later?
Store a note beside the report. Keep gate on required checks only. If the judge is ever allowed to add a failure, name that failure judge_flagged and still ignore the judge when a required check already failed. The judge must not turn failed back to zero.
Architect
How do you run v1 and v2 together?
Two fixture files, two reports, two baselines. Workers still on v1 keep citing the v1 report. The deploy pipeline promotes a version only when its own report says promote. Dashboards split by promptVersion so a v2 failure is not averaged away by v1's history.
Where does this sit with online evaluation?
Online sampling, if you add it, uses Lesson 52's classes: operational counts in the metric, personal text only in a store with a clock and a role check. Online data does not flow back into git. A drift alert can open a task to write a new synthetic fixture. It does not auto-edit the golden set.
What do you refuse when the suite blocks a launch?
You refuse to lower the gate to a pass rate, to delete the refund fixture, and to override block in the deploy script. You fix the prompt or the workflow, you record a new version if the contract changed, and you keep v1's checks intact for anything still serving v1.
How does Lesson 55 relate?
This suite proves the strings and traces. Lesson 55 proves a person can see "Waiting for approval" and cannot see a Contoso id, with the model route mocked. Neither lesson holds a live key. Together they cover behavior and the panel without pretending a screenshot is a grounding check.
Knowledge Check
1. What problem does this capability solve?
It stops a prompt or workflow change from shipping when a stored output violates a required safety check, and it does that without spending a model call.
2. What alternatives exist, and when would you choose each?
A unit test on parseTemplate fits the parser itself, and Lesson 47 already has that shape. This suite fits the recorded strings and traces you want to keep as a regression set. A human sample fits tone and rubric calibration. A live nightly job fits drift after a budget exists. A judge fits an extra signal. None of them replace a failed required check.
3. Which data, identity, and trust boundaries matter?
Fixtures are untrusted until loadFixture runs. Outputs are untrusted text. Traces must already be free of email and foreign ids. CI has no provider credential. promote is not a production identity.
4. What can fail, and how should the system respond?
Bad fixture shape throws fixture_rejected. A tool field, an extra key, a wrong template, a leaked id, an email, or a missing abstain sentence adds a { id, check } failure. gate returns block. The old version's suite keeps running.
5. How would you test quality, security, performance, and cost?
Quality is the required checks on template, grounding, and traces. Security is the loader's rejection of apiKey and @. Performance is a sub-second run on small files. Cost is the absence of a client, which you can review by reading runCohortSuite's parameters.
Practical Exercise
Add a tutor case whose output says "it is exact" and assert forbidden_claim. Add a trace whose reason contains priya@northwind.example and assert no_email. Confirm gate returns block for each report. Do not add a fetch mock.
Deliverable and Rubric
Submit the suite diagram, the scorer, the fixture list, a sample report, and a sentence on why a judge cannot clear no_tool.
Area
Weight
Conceptual accuracy and architecture
20%
Working implementation and code quality
25%
Security, privacy, and responsible AI
20%
Testing, reliability, and observability
20%
Documentation and decision rationale
15%
Production checklist:
The suite function has no HTTP client.
loadFixture rejects credential fields and emails.
Cohort checks cover template, tool, extra keys, and version.
Trace checks cover email, secrets, tenant fence, and empty spend.
Tutor checks cover support, forbidden claims, and abstain.
Any required failure blocks.
Baselines move with the case count.
Prompt versions are pinned and split.
Fixtures use public excerpts and synthetic ids.
promote is a citation, not a deploy.
Key Takeaways
Pull-request tests score fixtures. They do not call the provider.
loadFixture is the safety gate in front of the scorer.
cohort-reminder-v1 accepts one template key and nothing else.
A tool field fails the case even beside a valid template id.
Traces are part of the agent test.
Empty cohorts must show modelCalled: false.
Northwind traces must not name lrn_contoso.
Tutor cases stay inside the excerpt and abstain on a missing guarantee.
One failed required check fails the case.
gate ignores judges.
promote cites the report. Lesson 56 deploys.
New prompts get new versions. Old fixtures stay.
Production transcripts do not enter git.
The negative key test lives in memory, not in the fixture file.
Lesson 55 shows the same pause in a browser, still offline from the model.
Summary
Lesson 54 turns LLM and agent quality into a report a pipeline can block on. The reminder may only name cohort_reminder_v1. Traces may only carry counts, reasons, and the right tenant. Tutor answers may only say what the excerpt supports. All of that is checked with stored strings, a pinned version, and no live key. The panel that displays the pause is still untested as a browser flow. That is the next lesson.
Next Lesson Preview
End-to-End Testing with Playwright opens the operations panel in a real browser. You will sign in with a synthetic storage state, mock the reminder API, prove the browser never calls a model host, and show "Waiting for approval" for Northwind. The Playwright course is the reference for locators, fixtures, and traces. This lesson applies those tools to TechLearningPro's security rules.