|
| 1 | +name: Auto Fix Issue 370 Yjs Flush |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - '.github/workflows/auto-fix-issue-370-yjs.yml' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + fix: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: feat/issue-370-p0c-p1-knowledge-tree |
| 19 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | + fetch-depth: 0 |
| 21 | + - name: Patch Yjs no-op flush version bump |
| 22 | + run: | |
| 23 | + python3 <<'PY' |
| 24 | + from pathlib import Path |
| 25 | +
|
| 26 | + path = Path('backend/src/services/yjs.ts') |
| 27 | + text = path.read_text(encoding='utf-8') |
| 28 | + old = '''export function yFlush(noteId: string) { |
| 29 | + const room = rooms.get(noteId); |
| 30 | + if (!room) return; |
| 31 | + if (room.persistTimer) { |
| 32 | + clearTimeout(room.persistTimer); |
| 33 | + room.persistTimer = null; |
| 34 | + } |
| 35 | + try { persistToNotesTable(room); } catch {} |
| 36 | + try { |
| 37 | +''' |
| 38 | + new = '''export function yFlush(noteId: string) { |
| 39 | + const room = rooms.get(noteId); |
| 40 | + if (!room) return; |
| 41 | + const hadPendingPersist = Boolean(room.persistTimer); |
| 42 | + if (room.persistTimer) { |
| 43 | + clearTimeout(room.persistTimer); |
| 44 | + room.persistTimer = null; |
| 45 | + } |
| 46 | + // Rooms created only by a server-side replacement have no pending user edit. |
| 47 | + // Flushing them must not increment notes.version, otherwise immediate split undo |
| 48 | + // observes a false optimistic-lock conflict. |
| 49 | + if (hadPendingPersist) { |
| 50 | + try { persistToNotesTable(room); } catch {} |
| 51 | + } |
| 52 | + try { |
| 53 | +''' |
| 54 | + if old not in text: |
| 55 | + if 'const hadPendingPersist = Boolean(room.persistTimer);' in text: |
| 56 | + raise SystemExit(0) |
| 57 | + raise SystemExit('target yFlush snippet not found') |
| 58 | + path.write_text(text.replace(old, new, 1), encoding='utf-8') |
| 59 | + PY |
| 60 | + - name: Commit and push feature branch |
| 61 | + run: | |
| 62 | + if git diff --quiet -- backend/src/services/yjs.ts; then |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | + git config user.name "github-actions[bot]" |
| 66 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 67 | + git add backend/src/services/yjs.ts |
| 68 | + git commit -m "fix(yjs): avoid no-op version bump during flush" |
| 69 | + git push origin HEAD:feat/issue-370-p0c-p1-knowledge-tree |
0 commit comments