hogar compartido: colaboracion entre cuentas sobre Firestore

CloudKit sincroniza la base privada de un Apple ID: ni llega a Android ni deja
que dos cuentas editen el mismo plan (CKShare sigue sin existir en SwiftData).
El contenido de un hogar pasa por tanto a Firestore, y un dispositivo que entra
en un hogar construye el store local sin CloudKit — dos espejos escribiendo los
mismos objetos se pelean, que es justo lo que ya obligó a apagar el sync por
iCloud KV.

SwiftData sigue siendo el store local y el modo offline; HouseholdSyncService es
lo unico que habla con la red. Detecta cambios comparando una huella del
contenido de cada documento con la ultima sincronizada (el "shadow"), asi que no
hace falta instrumentar con updatedAt las treinta vistas que mutan modelos. Los
borrados van como tombstone: un borrado duro volveria desde cualquier miembro
que estuviera sin conexion.

Semanas y slots usan id derivado del contenido (2026-09-14, 5-dinner) para que
dos miembros que abren la misma semana escriban el mismo documento en vez de
crear dos, y para que los conflictos se resuelvan por slot y no por semana.

Incluye reglas de seguridad (solo miembros; los codigos de invitacion se pueden
leer por id pero no listar), pantalla de hogar en Ajustes con Sign in with Apple,
invitacion por codigo de 6 caracteres sin vocales ni 0/O/1/I, y la eleccion al
unirse entre llevarse los platos propios o adoptar los del hogar.

Fuera de esta fase: fotos de platos (necesitan Storage) y el cliente Android.

Refs #33

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013su1ttRiMeMYxkZJ1Y3246
This commit is contained in:
alexandrev-tibco
2026-09-12 13:00:38 +02:00
parent 66128e7a5c
commit 163fd6026a
22 changed files with 2261 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
import XCTest
/// The household screen has to be reachable from Settings and offer sign-in
/// before anything else none of which a unit test can see.
final class HouseholdUITests: XCTestCase {
func testHouseholdScreenIsReachableFromSettings() throws {
let app = XCUIApplication()
app.launchArguments += ["-AppleLanguages", "(en)", "-AppleLocale", "en_US", "UITEST_DISABLE_ANALYTICS"]
app.launch()
if !app.otherElements["home_root"].waitForExistence(timeout: 5) {
for id in ["onboarding_cta_welcome", "onboarding_cta_meal_windows", "onboarding_cta_weekends",
"onboarding_cta_calendar", "onboarding_cta_first_dishes",
"onboarding_cta_week_ready_skip", "onboarding_cta_paywall_skip"] {
let button = app.buttons[id]
if button.waitForExistence(timeout: 10) { button.tap() }
}
XCTAssertTrue(app.otherElements["home_root"].waitForExistence(timeout: 15), "Home never appeared")
}
app.buttons.matching(identifier: "gearshape").firstMatch.tap()
let settingsRow = app.buttons["Shared household"].firstMatch
XCTAssertTrue(settingsRow.waitForExistence(timeout: 10), "Household row missing from Settings")
settingsRow.tap()
XCTAssertTrue(app.navigationBars["Shared household"].waitForExistence(timeout: 5),
"Household screen did not open")
// Signed out: sign-in comes first, creating or joining is not offered yet.
XCTAssertTrue(app.buttons["Sign in with Apple"].waitForExistence(timeout: 5), "Apple sign-in button missing")
XCTAssertFalse(app.buttons["Create household"].exists, "Create must wait until there is an account")
let screenshot = app.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.name = "household-signed-out"
attachment.lifetime = .keepAlways
add(attachment)
try? screenshot.pngRepresentation.write(to: URL(fileURLWithPath: "/tmp/mealmood-household.png"))
}
}