A workflow is a chain of checks, not of prompts
With Cursor you can generate an Angular feature in a few minutes, and the risk is the same as ever: the code looks right and is not. A professional workflow is one in which every step has a check that does not depend on the agent: rules that declare how code is written, a task with a verifiable end criterion, tests that fail if the logic breaks, a build that tells the truth about sizes, a CI that repeats everything on every push. This article walks the chain on a real project, a task list with optimistic updates, and all the code was compiled and run with Angular 22.2.6.
It closes the series: you have seen the individual tools one by one, from rules to Agent Mode, from Plan Mode to hooks, from MCP to debugging. Here you line them up. An honest caveat: I wrote the article's code myself, by hand, and tested it; it is not the output of a Cursor session. It serves as a reference to compare what your agent produces against.
Step 1: the project rules, in a file every agent reads
The first investment is an instructions file in the project root. AGENTS.md is a good choice,
because the documentation of Cursor's rules
accepts it as a simple alternative to .cursor/rules, and because other tools read it too (you
see this in the comparison of the three products). The command
ng new can generate one for you: with --ai-config=cursor CLI 22.2.7 created, in the
test, an AGENTS.md with Angular best practices and a .cursor/mcp.json that connects
the editor to the CLI's MCP server. The values the option accepts are claude-code, cursor, gemini-cli,
open-ai-codex, vscode and none.
The generated file is a starting point, and it is worth reading because it says what Angular recommends today:
no standalone: true in decorators, because it is the default since version 20;
no explicit ChangeDetectionStrategy.OnPush, because since Angular 22 it is the default; signals for
state; inject() instead of constructor injection; native control flow instead of
*ngIf and *ngFor; and, for new singleton services, the @Service() decorator instead
of @Injectable({ providedIn: 'root' }). An agent that does not know the recent versions tends to
write the old syntax, the opposite of every line, and that is why rules matter.
On top of that base you add the rules of your project. The file below puts in seven, each with a reason: the first four fix how code is written, the last three the end-of-work check, which is the part no generator writes for you.
# Rules for the task-dashboard project
- Angular 22: standalone components, state with signal() and computed(), no NgModule.
- Writable state stays private in the service and is exposed with asReadonly().
- Arrays are never modified in place: create a copy with map, filter or spread.
That way the rollback of an optimistic update is a simple set() of the previous value.
- In templates: @if, @for and @empty; @for always has track on a stable id.
- Every new service has a spec with HttpTestingController and httpMock.verify().
- Before declaring a task finished, run `npx ng test --no-watch` and `npx ng build`
and report how many tests were run. If either fails, the task is not finished.
- Do not modify angular.json, package.json or existing tests without asking.
The rule on copying arrays and the one on the final check are linked. If state is never modified
in place, an optimistic update is undone by putting the old snapshot back, as you will see in the
service. And if "finished" means that ng test and ng build pass, the agent cannot
close a task that does not compile. For the .mdc format and for rules that activate by
path I refer you to the second article of the series.
Step 2: the project, with commands that do not need an agent
Creating a workspace is a deterministic operation: there is nothing to delegate and an agent session here is
just a slow way to launch a command. The only note is about the runtime: Angular 22 requires Node
^22.22.3, ^24.15.0 or 26 and later; with Node 24.11 the CLI stops with a clear message.
The generated project has three characteristics that change how you work with the agent: Vitest as the default test
runner, with jsdom (the testing guide says so), zoneless
as the default behavior since version 21 (zoneless guide)
and, in the production build's angular.json, size thresholds at 500 kB (warning) and 1 MB (error).
# Node 24.19.0 (Angular 22 requires ^22.22.3, ^24.15.0 or >=26)
npx @angular/cli@22 new task-dashboard --ai-config=cursor --style=css --ssr=false --skip-git --defaults
cd task-dashboard
npx ng test --no-watch
npx ng build
# Output of "ng test --no-watch" (Angular 22.2.6, Vitest 5.1.0, TypeScript 6.0.3; duration varies, ~1 s):
# Test Files 3 passed (3)
# Tests 5 passed (5)
#
# Output of "ng build" (same sizes in two runs; after the first feature with a lazy route):
# Initial total | 221.96 kB | 62.02 kB estimated transfer size
# Lazy chunk "task-list" | 1.92 kB | 928 bytes estimated transfer size
The numbers in the comments come from my own runs, not from a guide. After the feature with a lazy route the
initial bundle weighs 221.96 kB (62.02 kB transferred, the CLI's estimate) and the task-list route, in a
separate chunk, 1.92 kB. They are values from a minimal project: they serve to show you where to read your own measurements, not
to set a target. When the build exceeds a threshold the CLI warns or fails, and this is the check that
stops a dependency added without your knowing from silently bloating the bundle.
Step 3: the task, written as a contract
An effective prompt is not long, it is verifiable. It says what must happen, which constraints apply, what must not be touched and how the result is checked. The one below asks for the feature's most delicate function, the optimistic update of a state, and ends with the verification command: the agent runs it and pastes the output, you read it. It is a schema to adapt, not Cursor output.
Read AGENTS.md. In the src/app/features/tasks/ folder add the ability to
change the status of a task.
What it must do: updateStatus(id, status) in the TaskService updates the signal right away, then
calls PATCH /api/tasks/:id; if the server responds with an error it restores the previous
state and sets the error signal.
Constraints: follow AGENTS.md; do not touch the existing specs; add specs for the three cases
(success, immediate update, rollback on error).
Final check: run npx ng test --no-watch and npx ng build and paste the output.
Three choices deserve an explanation. "Do not touch the existing specs" stops the agent from making the test pass by modifying the test, a frequent vice when a check fails. Listing the three cases to cover removes the agent's freedom to write a single happy-path test. And requiring the pasted output shifts the burden of proof: if the number of tests is not there, the task is not demonstrated. If the function is bigger than that, start with Plan Mode and review the plan before letting it write.
The reference code: model, service, component
Model and service with signals
The model is a union type and an interface with readonly properties: a task's state is not
modified, it is replaced. The user-facing strings in the code below are in Italian (the tests assert them, and I did not
re-run the project): 'Impossibile caricare i task' means "Could not load the tasks",
'Aggiornamento non riuscito' means "Update failed", 'Nessun task' means "No tasks" and
Completati means "Completed".
export type TaskStatus = 'todo' | 'in-progress' | 'done';
export interface Task {
readonly id: string;
readonly title: string;
readonly status: TaskStatus;
}
The service keeps the two writable signals private and exposes them with asReadonly(), as the
signals guide recommends so as not to let
consumers modify the state. The core is updateStatus: it saves a snapshot of the current value,
replaces the array with a copy in which a single element changes, then sends the request. If the server
responds with an error, set(prima) restores everything.
import { HttpClient } from '@angular/common/http';
import { Service, computed, inject, signal } from '@angular/core';
import { Task, TaskStatus } from './task.model';
const API_URL = '/api/tasks';
@Service()
export class TaskService {
private readonly http = inject(HttpClient);
// Writable state stays private; outside the service it can only be read
private readonly _tasks = signal<readonly Task[]>([]);
private readonly _error = signal<string | null>(null);
readonly tasks = this._tasks.asReadonly();
readonly error = this._error.asReadonly();
readonly completionRate = computed(() => {
const tutti = this._tasks();
if (tutti.length === 0) return 0;
return Math.round((tutti.filter((t) => t.status === 'done').length / tutti.length) * 100);
});
loadTasks(): void {
this.http.get<Task[]>(API_URL).subscribe({
next: (tasks) => this._tasks.set(tasks),
error: () => this._error.set('Impossibile caricare i task'),
});
}
updateStatus(id: string, status: TaskStatus): void {
const prima = this._tasks(); // snapshot: the array is never modified in place
this._tasks.set(prima.map((t) => (t.id === id ? { ...t, status } : t)));
this.http.patch<Task>(`${API_URL}/${id}`, { status }).subscribe({
error: () => {
this._tasks.set(prima); // rollback: just put the snapshot back
this._error.set('Aggiornamento non riuscito');
},
});
}
}
The rollback works only because nobody modified the starting array. Had I used
push or assigned task.status = status on an object of the array, prima and the new
state would be the same object and there would be nothing to restore. It is a classic defect, and you see it with a test on the rollback, not by reading the code. @Service() is
the alternative to @Injectable({ providedIn: 'root' }) that CLI 22 recommends for new singleton
services; with a version of Angular earlier than 22 you still use @Injectable.
The component
The component declares neither standalone: true nor changeDetection: in Angular 22
the first is implicit and the second is OnPush by default, as the documentation of the
ChangeDetectionStrategy API reports. The template uses @if for the error, @for with
track task.id and @empty for the empty list. The track expression is what lets
Angular reuse DOM nodes instead of recreating them (control flow guide): with track $index, if the list changes order, a row's local state (the focus, the typed text) stays on the position instead of following the task.
import { Component, inject } from '@angular/core';
import { Task } from './task.model';
import { TaskService } from './task.service';
@Component({
selector: 'app-task-list',
template: `
@if (service.error(); as messaggio) {
<p role="alert">{{ messaggio }}</p>
}
<p>Completati: {{ service.completionRate() }}%</p>
<ul>
@for (task of service.tasks(); track task.id) {
<li>
<label>
<input type="checkbox" [checked]="task.status === 'done'" (change)="toggle(task)" />
{{ task.title }}
</label>
</li>
} @empty {
<li>Nessun task</li>
}
</ul>
`,
})
export class TaskList {
protected readonly service = inject(TaskService);
constructor() {
this.service.loadTasks();
}
protected toggle(task: Task): void {
this.service.updateStatus(task.id, task.status === 'done' ? 'todo' : 'done');
}
}
The service is protected because the template must read it but the rest of the program must not; the
checkbox reads from task.status and not from a local state, so the view always follows the
signal. What goes wrong here: loading in the constructor is fine for an example, but in a component
with route parameters you want an initialization that depends on the input.
Step 4: the tests the agent cannot get around
The tests use provideHttpClient() before provideHttpClientTesting(), in the order that the
HTTP testing guide recommends because the
second overrides parts of the first, and they end with http.verify(), which fails the test if an unexpected
request remains. The service test covers the three cases of the contract.
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { Task } from './task.model';
import { TaskService } from './task.service';
const DATI: Task[] = [
{ id: '1', title: 'Scrivere le regole', status: 'todo' },
{ id: '2', title: 'Configurare la CI', status: 'done' },
];
describe('TaskService', () => {
let service: TaskService;
let http: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
service = TestBed.inject(TaskService);
http = TestBed.inject(HttpTestingController);
});
afterEach(() => http.verify());
it('carica i task e calcola la percentuale di completamento', () => {
service.loadTasks();
http.expectOne('/api/tasks').flush(DATI);
expect(service.tasks()).toEqual(DATI);
expect(service.completionRate()).toBe(50);
});
it('aggiorna subito lo stato, prima della risposta del server', () => {
service.loadTasks();
http.expectOne('/api/tasks').flush(DATI);
service.updateStatus('1', 'done');
expect(service.completionRate()).toBe(100);
http.expectOne('/api/tasks/1').flush({ ...DATI[0], status: 'done' });
expect(service.completionRate()).toBe(100);
});
it('ripristina lo stato precedente se il server rifiuta', () => {
service.loadTasks();
http.expectOne('/api/tasks').flush(DATI);
service.updateStatus('1', 'done');
http.expectOne('/api/tasks/1').flush('errore', { status: 500, statusText: 'Server Error' });
expect(service.tasks()).toEqual(DATI);
expect(service.error()).toBe('Aggiornamento non riuscito');
});
});
The second test is the most important: it checks that the percentage rises to 100 before the request is answered, that is, that the update is truly optimistic. The third checks the restore. To know whether a test is worth anything it pays to break it on purpose: I removed the rollback line and two tests out of five failed, one of the service and one of the component. Had they all stayed green, I would have had proof that they checked nothing. The test names are in Italian, as are the data titles; they are labels and do not change the logic.
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { TaskList } from './task-list';
describe('TaskList', () => {
it('mostra i task, aggiorna subito la casella e torna indietro su errore', async () => {
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
const http = TestBed.inject(HttpTestingController);
const fixture = TestBed.createComponent(TaskList);
const el = fixture.nativeElement as HTMLElement;
http.expectOne('/api/tasks').flush([{ id: '1', title: 'Scrivere le regole', status: 'todo' }]);
await fixture.whenStable();
const casella = el.querySelector('input') as HTMLInputElement;
expect(el.textContent).toContain('Scrivere le regole');
expect(casella.checked).toBe(false);
casella.click(); // the user ticks the task
await fixture.whenStable();
expect(casella.checked).toBe(true);
expect(el.textContent).toContain('Completati: 100%');
http.expectOne('/api/tasks/1').flush('errore', { status: 500, statusText: 'Server Error' });
await fixture.whenStable();
expect(casella.checked).toBe(false);
expect(el.querySelector('[role="alert"]')?.textContent).toContain('Aggiornamento non riuscito');
http.verify();
});
});
The component test simulates the user: casella.click() changes the checkbox, whenStable()
lets the view update complete, and then the DOM is checked, not the signal. It is the right level to
catch a typical error, a correct service wired badly to the template. End-to-end Playwright
tests serve a different purpose and are not part of this example.
Step 5: lazy route and configuration
The route uses loadComponent with a dynamic import: Angular puts the component in a separate chunk,
and indeed the build showed one of 1.92 kB. The configuration adds provideHttpClient(withFetch()),
which uses the runtime's fetch API and is the form you need if one day you turn on server-side rendering.
import { Routes } from '@angular/router';
export const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'tasks' },
{
path: 'tasks',
// The component ends up in a separate chunk, downloaded only when needed
loadComponent: () => import('./features/tasks/task-list').then((m) => m.TaskList),
title: 'Task',
},
];
import { provideHttpClient, withFetch } from '@angular/common/http';
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideHttpClient(withFetch()),
provideRouter(routes),
],
};
The relationship between the two files is this: app.routes.ts decides which code is downloaded and when,
app.config.ts decides which services exist. If the agent adds an HTTP service and forgets the
provider, the service test passes (it has its own providers) and the running app fails: that is why it pays to have
at least one test that boots the root component with the real configuration.
Step 6: the CI repeats the checks on every push
Local checks are worth something only as long as someone runs them. The workflow below repeats them on every push to
main and on every pull request: it installs dependencies with npm ci, runs the tests and the
build, and cancels superseded runs of the same branch. The action versions are the current ones
as of 2026-11-13 according to the release pages (checkout 7.0.1, setup-node 7.1.0, major tag v7). It is a schema to
adapt: I did not run it on GitHub, I only validated the YAML syntax.
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
verifica:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npx ng test --no-watch
- run: npx ng build
The CI's Node must satisfy the same requirement as your machine, which is why
node-version: 24 and not a fixed version that ages. As for the rest, deployment depends on your
hosting and I do not propose it in the abstract: this project is browser-only and produces the
dist/task-dashboard folder; with server-side rendering (--ssr) the server and the way of
publishing change, not the method. The actual publishing you leave to a separate step, which you launch yourself after the checks.
Where the agent goes wrong, and how you spot it in review
The fixes to look for in review, on a project like this, are in practice these five. Read them as the outline of your review.
- State modified in place (
push, assignment to a field): the rollback and the signals stop working. - Syntax from an old version:
*ngIf, redundantstandalone: true,@Injectablewhere the rule says@Service(). - Tests that verify nothing, or that the agent modified to make them pass.
- Dependencies or configuration files touched without your asking.
- A build that passes because a size threshold was raised.
Each of these lines has an antidote in the workflow: the rules, the prompt contract, the rollback test, the ban on touching tests and configuration. When the agent goes wrong in a new way, do not blame the prompt: add a rule, so that next time the mistake does not get through. For the case where you are the one who has to find the cause of a failure, the method is in the seventh article.
Connecting Cursor to the Angular CLI with MCP
The last move concerns the end-of-work check. The Angular CLI includes an MCP server, described as
experimental in the documentation, which gives the agent
tools such as get_best_practices (the rules aligned with the version), list_projects and
run_target, with which to run test or build directly. The --read-only
argument registers only the tools that do not modify the project. It is the same file that
ng new --ai-config=cursor created (npx -y @angular/cli mcp); how to configure and how to
secure an MCP server is explained in the sixth article.
The warning does not change: npx -y runs the latest published version, so the tool must be
treated as third-party code.
What you can do now
You can set up an Angular project to work on with an agent: rules in AGENTS.md, a task
written as a contract with an end-of-work check, tests you verified by breaking them on purpose, a build
with size thresholds and a CI that repeats everything. You also know what to look at in review. You will not find in
these pages a percentage of time saved: it depends on the project and the task, and the only number that counts
is the one you measure yourself, with the same task done with and without the agent, as the
comparison of the tools describes. To restart from the beginning of the series there is the
complete guide to Cursor.
Frequently asked questions
How do you get Cursor to follow the project's Angular conventions?
With an instructions file read by the agent. ng new --ai-config=cursor generates an AGENTS.md with the practices recommended by Angular; you add your project's rules and the end-of-work check, that is, running tests and build before declaring it finished.
Do you need to write standalone: true and OnPush in Angular 22 components?
No. Standalone is the default since version 20 and OnPush has been since Angular 22, so declaring them is redundant. In an older project they must instead be specified, and the rule in the instructions file must say which version you use.
How do you check that a test generated by an agent is worth anything?
By breaking the code on purpose. If you remove the line the test is supposed to protect and the test stays green, it checks nothing. In the article's service, removing the rollback made two tests out of five fail.
Sources
- Angular: Angular CLI MCP Server setup - the server's tools (
run_target,get_best_practices), the--read-onlyoption, experimental status, consulted on 2026-11-13 - Angular: Develop with AI - configurations for AI assistants, Cursor among them, consulted on 2026-11-13
- Angular: Testing - Vitest and jsdom as the default setup of new projects, consulted on 2026-11-13
- Angular: Zoneless - zoneless by default since version 21, consulted on 2026-11-13
- Angular, API: ChangeDetectionStrategy - OnPush enabled by default, consulted on 2026-11-13
- Angular: Control flow -
@for,trackand@empty, consulted on 2026-11-13 - Angular: Signals -
asReadonly()to expose a signal without allowing it to be modified, consulted on 2026-11-13 - Angular: Testing HTTP requests - order of
provideHttpClientandprovideHttpClientTesting, consulted on 2026-11-13 - Cursor, documentation: Rules -
AGENTS.mdas an alternative to.cursor/rules, consulted on 2026-11-13 - actions/checkout: Releases - latest version 7.0.1 (2026-07-20), consulted on 2026-11-13
- actions/setup-node: Releases - latest version 7.1.0 (2026-10-08), consulted on 2026-11-13
The project was created with @angular/cli 22.2.7 (Angular 22.2.6, TypeScript 6.0.3, Vitest 5.1.0) in a temporary folder, with Node 24.19.0. The five tests were run twice and the build twice, with the same sizes. The YAML workflow was validated as syntax but not run on GitHub; the AGENTS.md and the prompt are schemas to adapt and were not given to Cursor, which is not installed on the test machine.

Commenti
Caricamento commenti...
Sign in to comment