Skip to content

Commit

Permalink
fix: correct AI comment faults
Browse files Browse the repository at this point in the history
Currently the AI comment writer is trusting the AI to write comment
markers. This means sometimes the syntax of a source file is broken by
comment generation. The instructions in the prompt were pretty clear, so
rather than --fixup'ing the previous commit I'm adding these changes
separately as an interesting case study of how different models behave.

Following this result, I am going to be removing mistral from the
comment writer. It is the most likely to misbehave.

I will also be removing gpt-4o-mini, which sometimes included source
lines despite the "no surrounding text" instruction.
  • Loading branch information
KernelDeimos committed Dec 2, 2024
1 parent f75010b commit b40d453
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 288 deletions.
9 changes: 0 additions & 9 deletions src/backend/src/services/HelloWorldService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ class HelloWorldService extends BaseService {
* @param {string} [options.subject] - The subject of the greeting. If not provided, defaults to "World".
* @returns {string} The greeting message.
*/

```javascript
11: async greet ({ subject }) {
12: if ( subject ) {
13: return `Hello, ${subject}!`;
14: }
15: return `Hello, World!`;
16: }
17: },
async greet ({ subject }) {
if ( subject ) {
return `Hello, ${subject}!`;
Expand Down
3 changes: 0 additions & 3 deletions src/backend/src/services/PuterHomepageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class PuterHomepageService extends BaseService {
* The parsed data is then assigned to the `manifest` property of the instance.
* @returns {Promise} A promise that resolves with the initialized PuterHomepageService instance.
*/
PuterHomepageService._init() {
// code here...
}
async _init () {
// Load manifest
const config = this.global_config;
Expand Down
23 changes: 0 additions & 23 deletions src/backend/src/services/ShareService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ const BaseService = require("./BaseService");
const { DB_WRITE } = require("./database/consts");
const { UsernameNotifSelector } = require("./NotificationService");


/**
401: * @classdesc ShareService - Handles share related operations.
402: */
class ShareService extends BaseService {
static MODULES = {
uuidv4: require('uuid').v4,
Expand Down Expand Up @@ -325,16 +321,6 @@ class ShareService extends BaseService {

install_share_endpoint ({ app }) {
// track: scoping iife
/**
401: * Method to grant permissions to the user after they have applied the share token.
402: *
403: * @param {Object} req - Request object containing the application request.
404: * @param {Object} res - Response object to send the response.
405: * @returns {Promise<void>} Resolves when the operation is completed.
406: */
407: ShareService.prototype.grant_permissions_on_apply = async function (req, res) {
408: // Your implementation here.
409: };
const router = (() => {
const require = this.require;
const express = require('express');
Expand Down Expand Up @@ -375,15 +361,6 @@ class ShareService extends BaseService {
}).attach(router);
}


/**
401 * @description Method to get a share by its UID.
402 *
403 * @param {Object} params - An object containing the UID of the share.
404 * @param {String} params.uid - The UID of the share.
405 *
406 * @returns {Promise<Share>} A promise that resolves to the Share object.
407 */
async get_share ({ uid }) {
const [share] = await this.db.read(
'SELECT * FROM share WHERE uid = ?',
Expand Down
7 changes: 0 additions & 7 deletions src/backend/src/services/SystemValidationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ const BaseService = require("./BaseService");
* @class
* @extends BaseService
*/

```javascript
class SystemValidationService extends BaseService {
```

```javascript
}
class SystemValidationService extends BaseService {
/**
* Marks the server is being in an invalid state.
Expand Down
9 changes: 0 additions & 9 deletions src/backend/src/services/WebServerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ class WebServerService extends BaseService {
*
* @returns {Promise<void>} A promise that resolves once the server is started.
*/
WebServerService.prototype['__on_start.webserver'] = async function () {
// ... rest of the method
}
async ['__on_boot.activation'] () {
const services = this.services;
await services.emit('start.webserver');
Expand Down Expand Up @@ -287,9 +284,6 @@ class WebServerService extends BaseService {
* @param {object} services - An object containing all services available to the web server.
* @returns {Promise<void>} A promise that resolves when the web server is fully started.
*/
WebServerService.prototype._init = async function(services) {
// ... existing code
};
get_server () {
return this.server_;
}
Expand All @@ -300,9 +294,6 @@ class WebServerService extends BaseService {
*
* @param {Object} services - An object containing all services.
*/
WebServerService._init.prototype._init = function(services) {
// Implementation goes here
};
async _init () {
const app = express();
this.app = app;
Expand Down
140 changes: 0 additions & 140 deletions src/backend/src/services/abuse-prevention/AuthAuditService.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,146 +88,6 @@ class AuthAuditService extends BaseService {
* @param {Object} params.extra - Additional information related to the event.
* @returns {Promise<void>} - A promise that resolves when the event is recorded.
*/


+++++ src/backend/src/services/abuse-prevention/AuthAuditService.js
/*
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const BaseService = require("../BaseService");
const { DB_WRITE } = require("../database/consts");

/**
* This class handles authentication audit services.
*
* @extends BaseService
*/
class AuthAuditService extends BaseService {
/**
* Modules used by this service.
*
* @static
* @type {Object}
*/
static MODULES = {
uuidv4: require('uuid').v4,
};

/**
* Initializes the AuthAuditService.
*
* @async
* @private
* @returns {Promise<void>} - A promise that resolves when initialization is complete.
*/
async _init () {
this.db = this.services.get('database').get(DB_WRITE, 'auth:audit');
}

/**
* Records an authentication audit event.
*
* This method logs an authentication audit event with the provided parameters.
* It generates a unique identifier for the event, serializes the requester,
* body, and extra information, and writes the event to the database.
*
* @param {Object} params - The parameters for the authentication audit event.
* @param {Object} params.requester - The requester information.
* @param {string} params.requester.ip - The IP address of the requester.
* @param {string} params.requester.ua - The user-agent string of the requester.
* @param {Function} params.requester.serialize - A function to serialize the requester information.
* @param {string} params.action - The action performed during the authentication event.
* @param {Object} params.body - The body of the request.
* @param {Object} params.extra - Additional information related to the event.
* @returns {Promise<void>} - A promise that resolves when the event is recorded.
*/
async record (parameters) {
try {
await this._record(parameters);
} catch (err) {
this.errors.report('auth-audit-service.record', {
source: err,
trace: true,
alarm: true,
});
}
}

/**
* Internal method to record an authentication audit event.
*
* @private
* @param {Object} params - The parameters for the authentication audit event.
* @param {Object} params.requester - The requester information.
* @param {string} params.requester.ip - The IP address of the requester.
* @param {string} params.requester.ua - The user-agent string of the requester.
* @param {Function} params.requester.serialize - A function to serialize the requester information.
* @param {string} params.action - The action performed during the authentication event.
* @param {Object} params.body - The body of the request.
* @param {Object} params.extra - Additional information related to the event.
* @returns {Promise<void>} - A promise that resolves when the event is recorded.
*/
async _record ({ requester, action, body, extra }) {
const uid = 'aas-' + this.modules.uuidv4();

const json_values = {
requester: requester.serialize(),
body: body,
extra: extra ?? {},
};

let has_parse_error = 0;

for ( const k in json_values ) {
let value = json_values[k];
try {
value = JSON.stringify(value);
} catch (err) {
has_parse_error = 1;
value = { parse_error: err.message };
}
json_values[k] = value;
}

await this.db.write(
`INSERT INTO auth_audit (` +
`uid, ip_address, ua_string, action, ` +
`requester, body, extra, ` +
`has_parse_error` +
`) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )`,
[
uid,
requester.ip,
requester.ua,
action,
JSON.stringify(requester.serialize()),
JSON.stringify(body),
JSON.stringify(extra ?? {}),
has_parse_error,
]
);
}
}

module.exports = {
AuthAuditService,
};
async _record ({ requester, action, body, extra }) {
const uid = 'aas-' + this.modules.uuidv4();

Expand Down
1 change: 0 additions & 1 deletion src/backend/src/services/auth/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const { UUIDFPE } = require("../../util/uuidfpe");

// This constant defines the namespace used for generating app UUIDs from their origins
const APP_ORIGIN_UUID_NAMESPACE = '33de3768-8ee0-43e9-9e73-db192b97a5d8';
const APP_ORIGIN_UUID_NAMESPACE = '33de3768-8ee0-43e9-9e73-db192b97a5d8';

const LegacyTokenError = class extends Error {};

Expand Down
28 changes: 0 additions & 28 deletions src/backend/src/services/database/SqliteDatabaseAccessService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ const { CompositeError } = require("../../util/errorutil");
const structutil = require("../../util/structutil");
const { BaseDatabaseAccessService } = require("./BaseDatabaseAccessService");


/**
* Class SqliteDatabaseAccessService
*
* This service provides
class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
static ENGINE_NAME = 'sqlite';

Expand Down Expand Up @@ -272,9 +267,6 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
* @description This method is used to register SQLite database-related commands with the dev-console service.
* @param {object} commands - The dev-console service commands object.
*/
241: _register_commands(commands) {
242: ...
243: }
svc_serverHealth.add_check('sqlite', async () => {
const [{ user_version }] = await this._requireRead('PRAGMA user_version');
if ( user_version !== TARGET_VERSION ) {
Expand Down Expand Up @@ -346,15 +338,6 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
* @param {Array<{statement: string, values: any[]}>} entries - An array of SQL queries and their corresponding parameters.
* @return {void} This method does not return any value.
*/
275: async _batch_write (entries) {
276: this.db.transaction(() => {
277: for ( let { statement, values } of entries ) {
278: statement = this.sqlite_transform_query_(statement);
279: values = this.sqlite_transform_params_(values);
280: this.db.prepare(statement).run(values);
281: }
282: })();
283: }
this.db.transaction(() => {
for ( let { statement, values } of entries ) {
statement = this.sqlite_transform_query_(statement);
Expand Down Expand Up @@ -397,17 +380,6 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
*
* @returns {Promise<void>} A promise that resolves when the migration is completed.
*/
303: async run_js_migration_ ({ filename, contents }) {
304: contents = `(async () => {${contents}})()`;
305: const vm = require('vm');
306: const context = vm.createContext({
307: read: this.read.bind(this),
308: write: this.write.bind(this),
309: log: this.log,
310: structutil,
311: });
312: await vm.runInContext(contents, context);
313: }
contents = `(async () => {${contents}})()`;
const vm = require('vm');
const context = vm.createContext({
Expand Down
Loading

0 comments on commit b40d453

Please sign in to comment.