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 56“React, Next.js, Node, PostgreSQL, LLMs, RAG, agents, and production AI apps”
CI/CD for AI-Powered Full-Stack Applications
On Thursday, TechLearningPro merged tutor-explain-v12.
Course progress0%
Focus
16 guided sections
Practice signal
Concept-first lesson
Career prep
Foundation builder
AI-Powered Full Stack Development · Lesson 56 · Full-Stack Security, Testing and Deployment
Lesson Overview
On Thursday, TechLearningPro merged tutor-explain-v12. Typecheck was green. Unit tests were green. The Playwright suite was green because it still talked to the in-process fake gateway. Staging then showed a warmer tutor that told learners they had finished the lesson. The same pull request had copied a workstation env file into the workflow so "the nightly check would just work." The credential never belonged in Git. The prompt change never belonged on main without the golden-set gate from the evaluation lesson.
Continuous integration is the set of checks that must pass before a change is allowed to merge. Continuous delivery is how a passing change becomes a named artifact and then a running release, with a human still able to stop production. An AI-powered product adds two gates a CRUD pipeline does not have. An eval gate compares a candidate prompt version to a stored baseline and fails closed when quality drops or a critical case fails. A secret scan rejects the diff, and ideally the history, when a credential or a private learner excerpt is about to be committed.
This lesson wires those gates into one pipeline for the learning platform. The pull-request job does not call a model provider. It runs deterministic tests, scans for secrets, builds an artifact identified by digest, and evaluates the tutor against checked-in fixtures. A separate nightly job may call a provider later, with a case cap and a spend cap, using a credential that exists only in the CI secret store. That credential is never written in this lesson.
The golden set is the public fixture set from the evaluation lesson. It contains no learner names, emails, or another tenant's notes.
Pull-request evaluation uses a fixture generator. Pass rate may not drop at all versus the baseline (maxDrop: 0) unless the change record says why.
A critical case failure blocks the merge even when the overall pass rate still looks fine.
Illustrative CI budget: the pull-request job stays under 12 minutes. The nightly live eval, when you add it, is capped at a small case count and a written spend ceiling. Replace both numbers with your runner's price card.
Learning Objectives
By the end of this lesson you will be able to:
Separate continuous integration (required checks on a change) from continuous delivery (promoting a digest through environments).
Explain why a green unit suite and a green Playwright run against a fake gateway do not prove a prompt change is safe.
Treat promptVersion, the golden set, and the eval baseline as release artifacts with owners.
Fail a merge when the candidate report has no baseline, a critical failure, or a pass-rate drop beyond maxDrop.
Keep provider calls off the pull-request path so a flaky model cannot block or bill every push.
Scan diffs for credential assignments, private-key blocks, and env files that are not examples.
Refuse to print a matched secret in the job log. Record the file, the line, and the rule name.
Identify a build by digest, not by a floating latest tag.
Require a human approval before production, and make that approval attach to the same digest CI built.
Write a workflow file that requests least-privilege token permissions and contains no credential value.
Describe a nightly live eval as a budgeted, separate job that still cannot overturn a failed deterministic check.
Test the promotion decision and the scanner with fixtures that are obviously not live keys.
/learn/ci-cd-automation for runners, artifacts, and environment protection. /learn/git for why a secret in history is still a secret after you delete the line.
You can read YAML and a TypeScript function. You do not need a cloud account or a provider key.
Detailed Core Concepts
What the pipeline is for
A pipeline exists so that "it worked on my laptop" is not the release process. For TechLearningPro the change might be a React state fix, a SQL migration, or a one-line prompt edit. Those changes do not carry the same risk, and they do not get to skip the checks that match their risk. The pipeline is the list of checks, the order they run, and the rule for what happens when one fails.
Stage
Question it answers
AI-specific note
Lint and typecheck
Does the code compile under the team's rules?
Prompt files that are TypeScript constants are typechecked too
Unit and contract tests
Do deterministic decisions still hold?
Completion still cannot be sourced from a draft
Browser tests
Does the player render a missing draft?
Fixture gateway only on pull requests
Secret scan
Did a credential or a private excerpt enter the diff?
Workflow files are in scope, not only application code
Eval gate
Did this prompt version hold the golden set?
Fixture model in CI. No live bill
Package
Which bytes will we deploy?
Digest, not a mutable tag
Promote
Who may run those bytes in production?
A person, on the same digest
Deterministic gates and eval gates
A unit test returns the same result for the same code. An eval gate returns the same result for the same prompt version, the same golden set, and the same fixture generator. The moment the pull-request job calls a live model, the gate becomes a sample. Temperature, provider load, and a silent model upgrade can fail a good prompt or pass a bad one. They can also spend money on every keystroke.
The fixture generator from the evaluation lesson is the right CI dependency. It is boring on purpose. The nightly job is where a live provider may score a small set, under a spend cap, and write a report a human reads. A live score may not flip a failed deterministic check to a pass. That rule is the same one the evaluation lesson set for a judge model.
Secret scanning
Secret scanning is a deterministic search for material that must not be in the repository. This lesson's scanner looks for three classes:
An assignment of a provider credential whose value uses the blocked live prefix tlp_live_. The lab prefix is fictional so the lesson file itself is safe to commit. Production scanners also use your vendor's published detectors. Verify those detector lists at implementation time.
A PEM private-key block.
A tracked file named .env or ending in .pem. .env.example is allowed when its values are empty or the literal replace-me.
The scanner reports file:line rule. It does not echo the matched value. Echoing the value copies the secret into the CI log, which is another store you now have to purge.
A scan of the latest commit is not a scan of history. If a key landed in an older commit, deleting the line in a new commit leaves the key in the git object store. The remediation is rotate first, then rewrite history with your security owner. This lesson's pull-request scan is the prevention control. History cleanup is the incident control.
Artifacts, digests, and environments
CI produces an artifact. Delivery moves that artifact. For the API image, the identity is the content digest. For the prompt, the identity is promptVersion plus the eval report's case count and pass rate. Promoting "whatever is on main" without recording the digest means production can drift from the commit you reviewed.
Three environments are enough for this product:
Environment
Who deploys
What is connected
Pull request
Nobody. Checks only
Fixture model, no production database
Staging
The pipeline, after required checks
Staging data, fixture or a capped provider
Production
A named approver
Production data, secret store, real provider
Staging is not a place to paste production learner rows so the demo looks real. Use synthetic tenants.
What changes when the product calls a model
Prompt text is source code. A change to PROMPT_VERSION or to the system string must run the eval gate even when no TypeScript signature changed. Golden-set edits must be reviewed as carefully as the prompt, because weakening mustNotClaim makes the gate lie. Baseline updates are a deliberate commit of a new SuiteReport, not a button that overwrites the baseline with whatever just failed.
Workflow files are production code. A pull request that only edits .github/workflows/ still runs the secret scan and the policy unit tests. It does not need a full browser suite if you split jobs, but it cannot skip the scan.
Architecture and Request Flow
The pull-request path never crosses into the provider. Production delivery is a later arrow, and only for a digest that already passed.
flowchart TB
subgraph dev [Developer]
PR[Pull request]
end
subgraph ci [CI on the pull request]
Tests[Typecheck unit contract Playwright]
Scan[Secret scan]
Eval[Fixture eval gate]
Pack[Artifact digest]
end
subgraph stores [Records]
Base[(Eval baseline)]
Golden[Golden fixtures]
end
subgraph cd [Delivery]
Stage[Staging]
Approve[Human approval]
Prod[Production]
end
subgraph later [Not on the pull request]
Nightly[Budgeted live eval]
Provider[Model provider]
end
PR --> Tests
Tests --> Scan
Scan --> Eval
Golden --> Eval
Base --> Eval
Eval --> Pack
Pack --> Stage
Stage --> Approve
Approve --> Prod
Nightly --> Provider
text
git push
-> required checks (no provider, no prod data)
-> secret scan fail: stop, rotate if the value was real
-> eval reject: stop, do not update the baseline to hide it
-> digest recorded
-> staging
-> human approves that digest
-> production secret store injects the credential
Trust boundary: the CI runner for pull requests is untrusted with production secrets and untrusted with learner content. Give it read access to the repo and nothing else. The production deploy identity is a different principal. It may read the secret store and may not be the identity that ran a fork's pull request.
Step-by-step Implementation
Package: packages/pipeline/. The workflow file lives at .github/workflows/tutor.yml. "strict": true. No provider SDK.
Step 1: Policy types
packages/pipeline/src/types.ts
typescript
/** A SuiteReport slice. The evaluation lesson owns the full scoring types. */
exportinterfaceEvalSummary{
promptVersion:string;
caseCount:number;
passRate:number;
criticalFailures:readonlystring[];
}
exportinterfacePromotionInput{
testsPassed:boolean;
secretScanClean:boolean;
candidate: EvalSummary;
/** Missing baseline fails closed. Do not treat "first run" as a pass. */
baseline: EvalSummary |undefined;
/** Zero means the candidate may not score below the baseline at all. */
promptVersionBumped stops a team from editing the system string while leaving the version id on the previous baseline. If the string did not change, the caller sets the flag true only when the version in the diff is still the baseline version and the prompt hash matches. The hash compare belongs next to the diff. The gate only sees the boolean so this function stays pure.
if(LIVE_KEY.test(line)) hits.push({ file, line: i +1, rule:"live_credential"});
if(PRIVATE_KEY.test(line)) hits.push({ file, line: i +1, rule:"private_key"});
}
return hits;
}
/** Log shape: rule and location. Never the line contents. */
exportfunctionformatHit(hit: ScanHit):string{
return`${hit.file}:${hit.line}${hit.rule}`;
}
.env.example does not match base === ".env". A live-prefix value inside the example file still matches LIVE_KEY. Placeholders such as replace-me do not.
Step 4: Workflow file
.github/workflows/tutor.yml
yaml
name: tutor-pipeline
on:
pull_request:
push:
branches:[main]
# Pull requests receive no production secrets. id-token is for a later
# deploy job that this lesson does not grant to forks.
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
steps:
-name: Checkout
uses: actions/checkout@v4
-name: Setup Node
uses: actions/setup-node@v4
with:
node-version:"22"
cache: npm
-name: Install
run: npm ci
-name: Typecheck
run: npx tsc --noEmit
-name: Unit tests
run: node --test
-name: Secret scan
run: node packages/pipeline/src/scan-cli.ts
-name: Fixture eval gate
run: node packages/pipeline/src/eval-cli.ts
env:
TUTOR_MODE: fixture
EVAL_MAX_DROP:"0"
# No provider credential is present in this job.
Pin third-party actions to a commit SHA before this file is a production control. A version tag can move. The lab uses the tag so the example stays readable. Say that in the review comment when you copy it.
There is no env: entry whose value is a key. A nightly live job, if you add one, may reference a store entry by name:
yaml
# Optional scheduled job. Do not merge this into the pull_request job.
# The value stays in the CI secret store. This file holds only the reference.
env:
TUTOR_MODE: live
EVAL_MAX_CASES:"20"
PROVIDER_KEY: ${{ secrets.TUTOR_PROVIDER_KEY }}
Fork pull requests must not receive TUTOR_PROVIDER_KEY. Configure the secret on a protected environment, not on the pull-request token.
Step 5: Run and clean up
From the repo root, with the package built or executed by the TypeScript strip runner your lesson 3 toolchain uses:
Nothing in the pull-request path opens a provider socket. Cleanup is leaving the fixture baseline committed and deleting any local .env you created for a later lesson. Do not "fix" a red scan by adding the matched prefix to an allow-list.
Security
Authentication of the pipeline. Protect main. Required checks are verify. A green review from the author is not a check.
Authorization of deploy. Production is a GitHub environment, or your host's equivalent, with required reviewers. The deploy role can pull one digest and read the secret store. It cannot push to main.
Least privilege.permissions: contents: read. Do not grant secrets: write or a cloud admin role to a job that runs on untrusted forks.
Input validation. The promotion function rejects a missing baseline, an empty eval, a bad digest, and a critical failure. Callers cannot pass a string reason to force allow_merge.
Secrets. Values live in the CI secret store and the production secret manager. Logs receive formatHit output only. Rotate any credential that reached a commit, even if the scan now fails the branch.
Tenant isolation. Golden fixtures are public course excerpts your team wrote. A job that checks out production database dumps into the runner has already broken isolation. Do not mount production backups as CI fixtures.
Supply chain.npm ci uses the lockfile. Review new dependencies. A prompt-eval helper that phones home is a data path for your golden set.
Prompt injection does not get a vote in CI. The model is not the approver. Even the nightly live eval is evidence for a human, not a required check that can be satisfied by a fluent score.
Error Handling
Condition
Pipeline result
Human next step
Tests fail
Block tests_failed
Fix the code. Do not skip the job
Secret hit
Block secret_scan
Remove the file from the branch. Rotate if the value was ever real
No baseline
Block missing_baseline
Commit an accepted report, do not copy the candidate over a failure
Critical eval failure
Block critical_eval
Change the prompt or the product check. Do not delete the case to go green
Pass-rate drop
Block pass_rate_drop
Inspect failing case ids. Raise maxDrop only in a reviewed policy change
Digest not sha256
Block bad_digest
Rebuild and publish an immutable digest
Nightly provider timeout
Record unavailable on the report
Do not fail the last good production deploy because a night job missed
A failed eval does not roll back production by itself. Production moves only when someone promotes a new digest. A failed nightly job alerts. It does not rewrite the baseline.
The live prefix in the test is a short marker, not a credential you can use anywhere. Add a fourth test that a pass-rate drop of any size blocks when maxDrop is 0, and a fifth that sha256:latest is bad_digest.
Performance and Cost
The pull-request job is on the critical path of every merge. Keep it deterministic and short.
Run typecheck, unit tests, secret scan, and the fixture eval on every pull request. Run the full Playwright suite on the same job while the suite is small. Split it when it dominates the 12-minute illustration.
Do not call a provider in that job. A 12-case live eval on every push multiplies tokens by the number of contributors and retries.
Cache npm by the lockfile. Do not cache the golden-set report across prompt changes. A stale cache that replays last week's pass is a false gate.
The nightly live job is the spend valve: EVAL_MAX_CASES, a timeout, and a dollar ceiling in the runner that kills the job. One scheduled run, not one run per commit.
Log case ids and pass bits. Logging full drafts into the CI log stores course text in a vendor you may not have under the same retention rule.
Build the container once and promote the digest. Rebuilding on the production runner "to be sure" can produce different bytes if the base image tag moved.
Illustrative ratio, not a quote: fixture eval cost is runner minutes. Live eval cost is tokens. The surprise bill in AI CI is a retry loop around a non-deterministic judge, not the secret scanner.
Knowledge Check
1. What problem does this pipeline solve?
It stops a prompt change or a credential from reaching main on the strength of unit tests alone. TechLearningPro gets a fail-closed eval decision, a secret scan that does not print the secret, and a production promotion that points at one digest.
2. What alternatives exist, and when would you choose each?
Fixture eval on the pull request fits every prompt change. A budgeted nightly live eval fits drift detection when the provider changes. A human rubric without a baseline fits a brand-new feature for one week, and then the accepted report becomes the baseline. Blocking on a live model inside the pull-request job fits nowhere in this design, because the signal is noisy and the bill tracks git traffic.
3. Which data, identity, and trust boundaries matter?
The pull-request runner may read the repository and may not read production secrets or learner data. The golden set is team-written public excerpts. The deploy identity is a different principal, used only after a human approves a digest. Forks do not inherit the nightly provider credential.
4. What can fail, and how should the system respond?
Test failures, scan hits, missing baselines, critical eval failures, pass-rate drops, and malformed digests all block with a stable reason. A nightly provider timeout alerts and leaves the last production digest in place. A secret that already landed is rotated, then removed from history with the security owner.
5. How would you test quality, security, performance, and cost?
Unit tests cover allow, critical block, missing baseline, and the scanner's log redaction. Security review checks workflow permissions and that production secrets are not in the pull-request environment. Performance review checks job duration. Cost review checks that the live provider is absent from pull requests and capped on the schedule.
Hands-on Assignment
Lab note. Use fixture mode. Do not create a provider key. The blocked prefix in the tests is a marker, not a secret to reuse.
Problem. Add the TechLearningPro tutor pipeline: deterministic checks, a secret scan, and an eval gate that cannot be satisfied by editing the baseline in place.
Tasks.
Draw the diagram. Mark the pull-request runner as forbidden to hold TUTOR_PROVIDER_KEY.
Implement decidePromotion and scanText with the tests in this lesson.
Add the pass-rate and bad-digest tests named above.
Put .github/workflows/tutor.yml in the repo without a credential value. Set permissions to contents read.
Write six controls: owner and evidence. Include required checks, baseline presence, critical cases, secret log redaction, digest format, and production approvers.
State what you would do if scanText matched a real vendor key in an old commit. The first verb is rotate.
Deliverable. Diagram, source with no secrets, test output, the six-row control table, and a trade-off note on fixture eval versus nightly live eval.
Challenge. A second tenant's private lesson excerpt is proposed as a golden case because "it failed in production." Refuse it. Describe the synthetic case you would write instead, and the log fields you would keep (case id, prompt version, check name) so the private excerpt never enters CI.
Rubric. 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%.
Common Mistakes
Calling the provider on every pull request. Symptom: flaky red builds and a token bill that tracks commits. Cause: treating eval like a unit test against a live dependency. Fix: fixture gate on the pull request, capped live eval on a schedule.
Updating the baseline to match a failure. Symptom: the gate is always green and the tutor still invents completion. Cause: the candidate report was copied over the baseline to unblock a release. Fix: baseline updates are a separate reviewed commit after a real prompt improvement.
Printing the matched secret in the log. Symptom: the CI log is now a secret store. Cause: console.log(line) inside the scanner. Fix: log formatHit only, then rotate.
Allow-listing .env because local dev needs it. Symptom: the next credential commit is invisible. Cause: a broad ignore rule. Fix: track .env.example only. Keep .env in .gitignore and still scan the diff so a force-add is caught.
Deploying latest. Symptom: production is not the commit that passed eval. Cause: the deploy job pulled a tag that moved. Fix: deploy the sha256 digest the verify job recorded.
Letting a fork job read production secrets. Symptom: an external pull request exfiltrates the provider key. Cause: secrets were repository-wide instead of environment-scoped. Fix: put the key on the protected production environment.
Deleting a critical case to go green. Symptom: pass rate recovers and the Monday bug returns. Cause: the golden set was treated as annoyance. Fix: review golden-set diffs with the same bar as prompt diffs.
Skipping CI on workflow-only changes. Symptom: a workflow edit injects a secret and nothing runs. Cause: path filters excluded .github. Fix: secret scan and policy tests run on those paths too.
Using production learner rows as fixtures. Symptom: personal data in the repo and in runner caches. Cause: "real data tests better." Fix: synthetic excerpts written by the team.
Retrying a live eval until it passes. Symptom: spend spikes and the recorded score is the lucky sample. Cause: a loop around a non-deterministic judge. Fix: one scheduled attempt, then a human.
Summary
A full-stack pipeline already had to typecheck, test, and promote a digest. An AI-powered pipeline adds an eval gate that fails closed against a baseline, and a secret scan that reports locations without copying values into the log. Pull requests stay on fixtures. Production is a human approval of that same digest. The provider credential, when you eventually need one, is injected from a store the pull-request runner cannot read. /learn/ci-cd-automation goes deeper on runners and promotion mechanics. The next lesson makes the artifact this pipeline builds runnable on a laptop, with the same boundary.
Next Lesson Preview
Docker, Containers and Local Development Environments turns the digest into a local stack: API, lesson player, PostgreSQL, and a fixture model sidecar. You will see why "works on my machine" survives a green CI job when the laptop is not running the image CI built.
Further Reading
GitHub Actions workflow syntax for on, permissions, jobs, and environments. Re-check the permission keys when you copy the file.