# Teaching guide — Session 2

## Diagnose, improve and check

Continue the S1 app. The minimum outcome is **a diagnosed error, one tested improvement, a security review and a functionality and access test**. The six improvements form a catalogue: learners do not need to do them all. Photos are an optional advanced challenge.

## Format and starting point

Allow roughly 2.5 hours of self-paced work over one or several sittings. In a group, adapt the pace and keep presentations optional. Learners need a browser, an authorised account, their S1 app and access to its spreadsheet and project. Use fictional data; there is no need to switch to a personal account if the organisation provides an authorised environment.

Keep the restaurant analogy: **dining room / frontend** (`Index.html`), **kitchen / backend** (`Codi.gs`), **pantry / database** (Sheets) and, if needed, **storeroom / storage** (files).

## Teacher preparation

- Prepare the S1 reference with fictional data. Check `ID_DEL_FULL`, `Registres`, headers and `comprovaConnexio`.
- Create a practice copy of spreadsheet and project. The code’s ID must point to the copy, not the original spreadsheet. Keep both working files.
- Rehearse `/dev`: **Deploy → Test deployments → Web app**. Only project editors can access it; it runs the latest saved code.
- Keep the deployed `/exec`. Saving code does not update it. Do not deploy the deliberate error.
- Choose design or search as the first improvement. Check the plan and tests; an AI answer is not evidence that it works.
- Prepare two browser profiles to check authorised and denied access. The app does not need to be open to everyone.

## Suggested path: 150 minutes

| Block | Minutes | Observable result |
|---|---:|---|
| Recover the project and make copies | 15 | Test spreadsheet and code identified |
| Reproduce a reversible error | 25 | Message and steps recorded |
| Interpret, fix and retest | 20 | The copy works again |
| Break | 10 | |
| One small improvement | 40 | Reviewed plan, change and tests |
| Security and access | 20 | Settings and accounts checked |
| Deployment and results | 20 | Same /exec and repeated tests |

## Debugging exercise, step by step

1. Open `/dev` on the copy and check it works before changing anything.
2. If `doGet()` loads `Index`, rename only that HTML file to `Inici`, save and reload `/dev`. Do not delete a random line.
3. Read the error and record what was expected, what happened and how to reproduce it. Give AI the error and current code, without private data.
4. Ask for a likely cause and smallest fix. Restoring `Index` may be enough: do not require a rewrite.
5. Save, retest `/dev` and check reading, a valid write and invalid input. The test must write to the copy.
6. If recovery fails, restore the saved files. Reverting code does not recover deleted data.

## Supporting the improvement

- **Design:** preserve features, contrast, keyboard access and phone use.
- **Search:** label that it filters loaded records, not necessarily the whole spreadsheet.
- **Summary:** state the scope; compare count and average with three manually calculated entries and an empty dataset.
- **Edit/delete:** advanced. Record IDs must be stable; row positions are not. Before adding a column, review migration, headers and existing data. Test concurrency and cancellation.
- **Pagination:** advanced. Displaying ten rows does not guarantee reading only ten. Review backend limits and what happens if rows change between requests.
- **Photos:** advanced and optional. Agree access, sizes, formats and authenticated retrieval first. A Drive URL does not guarantee a thumbnail. Do not make the folder public or accept permissions automatically. Leave the challenge pending if the design cannot be verified.

## Deployment and completion

After tests pass on the copy, move only tested changes to the intended project and check its spreadsheet ID. Use **Manage deployments → Edit → New version** to preserve `/exec`. Repeat tests and check access. Sharing is optional; a private app is valid too.

The course menu counts four goals: diagnosis, at least one improvement, security and access. Previous catalogue progress is preserved. Switching projects restores each app’s state without reusing another app’s link.

## When someone gets stuck

| Symptom | Useful check |
|---|---|
| The change is not visible | /dev or /exec? Was the deployed version updated? |
| It writes to the original spreadsheet | Check the copy’s ID before continuing |
| Header error | Keep the exact order; review the migration plan |
| Search misses an old record | It may be outside the loaded list |
| Another account cannot enter | That may be correct for a private app |
| AI says “tested” | Ask for environment, steps and observed result |

Do not request credentials or personal data for support. Use the [test worksheet](../../fitxa-proves-s2-s3.en.html) to record evidence. If time is short, finish the loop and one improvement before attempting photos or migrations.

## Technical sources

- [Web apps and the /dev test URL](https://developers.google.com/apps-script/guides/web).
- [Versions and deployments](https://developers.google.com/apps-script/concepts/deployments).
- [Asynchronous communication with google.script.run](https://developers.google.com/apps-script/guides/html/communication).

Content reviewed: 25 October 2026. Site checks and simulations do not replace testing each app in an authorised Google account.
