Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Integration Tests

on:
pull_request:
branches: [main]
workflow_dispatch: # remove after initial CI validation

jobs:
integration:
runs-on: ubuntu-latest
env:
OVERLEAF_GIT_AUTHOR_NAME: OverleafMCP CI
OVERLEAF_GIT_AUTHOR_EMAIL: ci@overleafmcp.test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- name: Write projects.json from secrets
run: |
cat > projects.json << 'EOF'
{
"projects": {
"example_project": {
"name": "Example Project",
"projectId": "${{ secrets.EXAMPLE_PROJECT_ID }}",
"gitToken": "${{ secrets.EXAMPLE_PROJECT_TOKEN }}",
"readOnly": false
},
"readonly_example_project": {
"name": "ReadOnly Example Project",
"projectId": "${{ secrets.READONLY_PROJECT_ID }}",
"gitToken": "${{ secrets.READONLY_PROJECT_TOKEN }}",
"readOnly": true
}
}
}
EOF
- name: Run integration tests
run: node --test test/integration.test.js
- name: Restore test files on failure
if: failure()
run: node test/restore.js
18 changes: 18 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Unit Tests

on:
pull_request:
branches: [dev, main]
workflow_dispatch:

jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: node --test test/unit.test.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
temp/
spec/
projects.json
.env
*.log
10 changes: 8 additions & 2 deletions overleaf-git-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const SECTION_LEVELS = {
subparagraph: 6,
};

export const PREVIEW_MAX_LENGTH = 100;

export class OverleafGitClient {
constructor(projectId, gitToken, tempDir) {
this.projectId = projectId;
Expand Down Expand Up @@ -238,7 +240,11 @@ export class OverleafGitClient {

async readFile(filePath) {
await this.cloneOrPull();
return fs.readFile(this._safePath(filePath), 'utf-8');
const content = await fs.readFile(this._safePath(filePath), 'utf-8');
// Normalise Windows-style CRLF to LF. Overleaf's git server uses CRLF on
// some projects. Without this, str_replace and insert_before/after anchors
// constructed with LF would fail to match even when visually identical.
return content.replace(/\r\n/g, '\n');
}

/**
Expand Down Expand Up @@ -271,7 +277,7 @@ export class OverleafGitClient {
const contentStart = entry._cmdEndIndex;
const contentEnd = i + 1 < flat.length ? flat[i + 1].startIndex : content.length;
entry.content = content.substring(contentStart, contentEnd).trim();
entry.preview = entry.content.substring(0, 100).replace(/\s+/g, ' ');
entry.preview = entry.content.substring(0, PREVIEW_MAX_LENGTH).replace(/\s+/g, ' ');
delete entry._cmdEndIndex;
});

Expand Down
Loading
Loading