Skip to content

App Builder - Unit and Integration tests#7

Open
eshurakov wants to merge 2 commits intomainfrom
eshurakov/app-builder-file-tree-blob-api
Open

App Builder - Unit and Integration tests#7
eshurakov wants to merge 2 commits intomainfrom
eshurakov/app-builder-file-tree-blob-api

Conversation

@eshurakov
Copy link
Contributor

This pull request introduces improvements to the Cloudflare App Builder project focusing on enhanced test coverage.

Testing & CI Improvements

  • Added integration tests for the App Builder.

API Schema Additions

  • Introduced new API schemas for the /tree and /blob endpoints, defining types and validation for tree and blob responses.

* @param path - Optional path to a subdirectory (defaults to root)
* @returns Array of tree entries with name, type, oid, and mode
*/
async getTree(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated, can we reuse the git implementation from here?

* @param path - Path to the file
* @returns File content (utf-8 or base64 encoded), encoding type, size, and blob SHA
*/
async getBlob(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also duplicated and the return types are mismatching?

message: error instanceof Error ? error.message : 'Path not found',
}),
{
status: 404,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return 404 also for 'Error(Path not found: ${normalizedPath})' and 'Error(Path is not a directory: ${normalizedPath})'. It depends on the quality we want for this API, but an optional improvement would be to handle not found cases explicitly by cascading the error from getTree

message: error instanceof Error ? error.message : 'File not found',
}),
{
status: 404,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above. Same thing here.

// Handle tree requests (GET /apps/{app_id}/tree/{ref})
const treeMatch = pathname.match(TREE_PATTERN);
if (treeMatch && request.method === 'GET') {
const decodedRef = decodeURIComponent(treeMatch[2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: decodeURIComponent() can throw on malformed percent-encoding

If a client sends an invalid URL escape sequence in the {ref} segment (e.g. %E0), decodeURIComponent() throws URIError: URI malformed, which will bubble up as an unhandled exception (500). Consider guarding decoding and returning a 400 for invalid encoding.

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 9, 2026

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
cloudflare-app-builder/src/index.ts 143 decodeURIComponent() can throw on malformed percent-encoding (unhandled 500 risk)
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
cloudflare-app-builder/src/git/git.ts 432 console.log usage in library code (may be noisy in production logs)
Files Reviewed (6 files)
  • cloudflare-app-builder/src/index.ts - 1 issue
  • cloudflare-app-builder/src/handlers/files.ts - 0 issues
  • cloudflare-app-builder/src/handlers/git-protocol.ts - 0 issues
  • cloudflare-app-builder/src/git-repository-do.ts - 0 issues
  • cloudflare-app-builder/src/types.ts - 0 issues
  • cloudflare-app-builder/package.json - 0 issues

Fix these issues in Kilo Cloud

@eshurakov
Copy link
Contributor Author

thank you @marius-kilocode, PR is ready for another pass

"@types/better-sqlite3": "^7.6.13",
"@types/jsonwebtoken": "^9.0.9",
"@types/node": "^22.10.1",
"better-sqlite3": "^12.6.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can already use: 12.6.2, same applies for the other new deps and their patch releases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still the old version?

try {
db.close();
} catch {
// Ignore - might already be closed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not log this?

@@ -0,0 +1,72 @@
/**
* Test utilities for GitVersionControl unit tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does't appears really domain specific to git. It rather looks like common code that should be sharable and reusable?

run: pnpm --filter app-builder typecheck

- name: Run app-builder tests
run: pnpm --filter app-builder test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused here should we not run the integration tests?

echo ""

if pnpm exec tsx "$test_file"; then
TOTAL_PASSED=$((TOTAL_PASSED + 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we do all of this manually? Should we not use a proper test runner instead?


if (result.status === 201 && result.body.success === true) {
logSuccess('Init with valid special chars (underscore, hyphen) succeeds');
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why we are returning true or false here? We need assertions here or not and a proper test framework to detect failures.

import { logger } from '../utils/logger';
import type { Env } from '../types';

const notFoundPatterns = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really hacky model reward hack, once any error string changes the logic changes. We should introduce either proper error codes or error implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants