Merged
Conversation
#1861) * fix: prevent defaults being set to undefined, and interpret numbers and enums as strings. * chore: Auto-format JavaScript files with Prettier
Contributor
Reviewer's GuideRefactors record path handling and validation, tightens repository/path resolution, updates version/APIs for the web server, ensures protobuf replies are converted to plain objects, and changes transfer tasks to use structured user tokens with additional metadata. Sequence diagram for protobuf reply handling and plain-object conversionsequenceDiagram
participant CoreServer
participant WebSocket as g_core_sock
participant MessageHandler as onMessageHandler
participant MsgRegistry as g_msg_by_id
CoreServer->>WebSocket: send envelope frame
WebSocket-->>onMessageHandler: message event(reply, msg_type)
onMessageHandler->>MsgRegistry: lookup msg_info by msg_type
MsgRegistry-->>onMessageHandler: msg_info(type, field_name, field_id)
alt handler exists
onMessageHandler->>onMessageHandler: determine which_field
onMessageHandler->>MsgRegistry: resolve actual_entry by which_field
MsgRegistry-->>onMessageHandler: actual_entry(type)
onMessageHandler->>onMessageHandler: resolve_type = actual_entry.type or msg_info.type
onMessageHandler->>onMessageHandler: msg = resolve_type.toObject(msg, defaults=true, longs=String, enums=String)
onMessageHandler->>MessageHandler: f(msg)
else no handler
onMessageHandler->>onMessageHandler: ignore or log
end
Class diagram for updated Record and Repo path handlingclassDiagram
class Record {
-string #key
-object #loc
-object #repo
-number #error
-string #err_msg
-boolean #alloc
_pathToRecord(uid string, basePath string) string
isPathConsistent(a_path string) boolean
}
class Repo {
+Repo(id string)
+resolveFromPath(file_path string) Repo
+pathType(file_path string) PathType
+id() string
-string path
}
class PathType {
<<enumeration>>
UNKNOWN
/* other members not shown */
}
class PosixPathUtil {
+normalizePOSIXPath(a_posix_path string) string
+splitPOSIXPath(a_posix_path string) string[]
}
Record ..> Repo : validates
Repo ..> PosixPathUtil : uses
Repo --> PathType : returns
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
Record.isPathConsistentyou removed_comparePathsand now rely on strict string equality; consider whether this loses any intended normalization behavior (e.g., trailing slashes, case, repo.path leading slash) and either restore a dedicated path comparison helper or extend the current logic to cover those cases explicitly. - The new
Repo.resolveFromPathdoes a full scan ofg_db.repoon each call and treats any path that normalizes differently as invalid; if this endpoint is on a hot path, consider caching repo paths and/or being more precise about which normalization patterns you want to reject instead of blanketcanonical !== file_path. - In
tasks.jsthe new usage ofUserToken(includingUserToken.formatUserTokenForTransferTaskandformatUserToken) assumes this class is available in the module; double-check that it is required/imported correctly and thatget_token()failure modes are compatible with the priorg_lib.getAccessTokenbehavior for these task flows.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Record.isPathConsistent` you removed `_comparePaths` and now rely on strict string equality; consider whether this loses any intended normalization behavior (e.g., trailing slashes, case, repo.path leading slash) and either restore a dedicated path comparison helper or extend the current logic to cover those cases explicitly.
- The new `Repo.resolveFromPath` does a full scan of `g_db.repo` on each call and treats any path that normalizes differently as invalid; if this endpoint is on a hot path, consider caching repo paths and/or being more precise about which normalization patterns you want to reject instead of blanket `canonical !== file_path`.
- In `tasks.js` the new usage of `UserToken` (including `UserToken.formatUserTokenForTransferTask` and `formatUserToken`) assumes this class is available in the module; double-check that it is required/imported correctly and that `get_token()` failure modes are compatible with the prior `g_lib.getAccessToken` behavior for these task flows.
## Individual Comments
### Comment 1
<location path="core/database/foxx/api/record.js" line_range="75-78" />
<code_context>
+ * @returns {string|null} - the path to the record or null if error
*/
- _pathToRecord(loc, basePath) {
+ _pathToRecord(uid, basePath) {
const path = basePath.endsWith("/") ? basePath : basePath + "/";
- if (loc.uid.charAt(0) == "u") {
- return path + "user/" + loc.uid.substr(2) + "/" + this.#key;
- } else if (loc.uid.charAt(0) == "p") {
- return path + "project/" + loc.uid.substr(2) + "/" + this.#key;
+ if (uid.charAt(0) === "u") {
+ return path + "user/" + uid.substr(2) + "/" + this.#key;
+ } else if (uid.charAt(0) === "p") {
</code_context>
<issue_to_address>
**suggestion:** Avoid deprecated `substr` and prefer `slice` for uid extraction.
This still calls `uid.substr(2)` for both user and project prefixes. Since `substr` is deprecated, please switch to `uid.slice(2)` to use the modern equivalent without changing behavior.
```suggestion
if (uid.charAt(0) === "u") {
return path + "user/" + uid.slice(2) + "/" + this.#key;
} else if (uid.charAt(0) === "p") {
return path + "project/" + uid.slice(2) + "/" + this.#key;
```
</issue_to_address>
### Comment 2
<location path="core/database/foxx/api/record.js" line_range="201-202" />
<code_context>
- this.#repo = g_db._document(this.#loc.new_repo);
-
- if (!this.#repo) {
+ const new_repo = g_db._document(this.#loc.new_repo);
+ if (!new_repo) {
this.#error = error.ERR_INTERNAL_FAULT;
this.#err_msg =
</code_context>
<issue_to_address>
**issue (bug_risk):** In the in-flight branch, `this.#repo` is no longer updated, which may break callers relying on it after `isPathConsistent`.
`new_repo` is now local and `this.#repo` is only updated in the non–in-flight branch, so callers that expect `isPathConsistent` to leave `this.#repo` pointing at the resolved repo may now see stale state. Please update `this.#repo` to `new_repo` after a successful resolution to preserve the previous behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+75
to
+78
| if (uid.charAt(0) === "u") { | ||
| return path + "user/" + uid.substr(2) + "/" + this.#key; | ||
| } else if (uid.charAt(0) === "p") { | ||
| return path + "project/" + uid.substr(2) + "/" + this.#key; |
Contributor
There was a problem hiding this comment.
suggestion: Avoid deprecated substr and prefer slice for uid extraction.
This still calls uid.substr(2) for both user and project prefixes. Since substr is deprecated, please switch to uid.slice(2) to use the modern equivalent without changing behavior.
Suggested change
| if (uid.charAt(0) === "u") { | |
| return path + "user/" + uid.substr(2) + "/" + this.#key; | |
| } else if (uid.charAt(0) === "p") { | |
| return path + "project/" + uid.substr(2) + "/" + this.#key; | |
| if (uid.charAt(0) === "u") { | |
| return path + "user/" + uid.slice(2) + "/" + this.#key; | |
| } else if (uid.charAt(0) === "p") { | |
| return path + "project/" + uid.slice(2) + "/" + this.#key; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
Description
How Has This Been Tested?
Artifacts (if appropriate):
Tasks
Summary by Sourcery
Improve path consistency validation, repository resolution, and API version handling, and enrich transfer tasks with detailed token metadata.
Bug Fixes:
Enhancements:
Tests: