DEV Community

Bruce Mcpherson
Bruce Mcpherson

Posted on

Bringing Apps Script to the desktop – the why, where and how of gas-fakes

A brief summary on approaching parity of Google Apps Script methods and classes, some of the 'extras' gas-fakes provides for platform variety, production, development and testing and glimpse of some of the techniques used to get there.

Introduction: The Challenge of the Scripting Layer

Google Apps Script (GAS) is a powerful tool for extending Google Workspace, automating workflows, and building lightweight backend services. It excels at rapid prototyping and integration within the Google ecosystem. However the limitations of the GAS environment (its proprietary runtime, laborious deployment cycle, and lack of modern tooling and debugging) become significant bottlenecks.

We love the power and integration of GAS, but we require the debuggability and flexibility of a modern Node.js environment.

This is the problem that gas-fakes is designed to address.

gas-fakes is an architectural emulation layer designed to bring the entire GAS runtime experience (its APIs, its behaviors, and its constraints) into a robust, controllable Node.js environment. It allows developers to write GAS-like code while leveraging the full power of modern software engineering practices.

gas-fakes what

1. The Path to Parity: Emulating the GAS Runtime

The core challenge in building gas-fakes is the fundamental mismatch between the GAS execution model and the Node.js event loop. GAS is inherently asynchronous, relying on a managed, proprietary execution environment. Node.js, is designed for high-throughput, asynchronous execution and non-blocking I/O.

Our architectural approach to achieving parity focuses on accurate API simulation and execution model transformation.

The API Contract: Discovery Documents and REST

The foundation of GAS is its reliance on Google's ecosystem of REST APIs, exposed through its own managed runtime. We've mapped the exact schema, parameters, and expected responses of every GAS service (e.g., SpreadsheetApp, GmailApp). This allows gas-fakes to treat the GAS environment as a highly structured, predictable API contract.

The Execution Model: Synchronous Emulation via Worker Threads

The most complex hurdle is the transformation of GAS's asynchronous API calls (which often feel synchronous to the developer) into a predictable, synchronous-feeling flow within Node.js.

We achieve this by employing Worker Threads and Atomics.

  1. Worker Isolation: When a GAS method is called (e.g., SpreadsheetApp.getActiveSpreadsheet().getRange().getValue()), the request is routed to a dedicated Worker Thread. This isolates the simulated GAS execution from the main Node.js event loop, preventing blocking while maintaining the illusion of synchronous execution.
  2. Asynchronous-to-Synchronous Bridge: The Worker Thread executes the simulated API call. Instead of returning a standard Promise, we use Atomics to manage shared memory state between the Worker and the main thread. This allows the main thread to effectively "wait" for the combined result from the Worker, mimicking the blocking behavior of the original GAS runtime, while allowing the worker to execute multiple asynchronous activities.

The Importance of Behavioral Oddities

A perfect API contract is insufficient. GAS has numerous subtle, undocumented behaviors such as rate limiting quirks, specific error codes, divergences from the associated API behavior, ID transformations, and timing dependencies that need to be understood and emulated for true parity.

A significant part of the gas-fakes development process is the meticulous documentation and reproduction of these behavioral oddities. We don't just emulate the happy path; we emulate the edge cases and the developer experience of the live GAS environment, ensuring that code written in gas-fakes behaves identically to how it would in production.

🧪 Rigorous Testing Regime: gas-fakes fidelity assurance

To validate the claim of behavioral parity, gas-fakes operates under a massive, dual-environment testing regime. We maintain a comprehensive suite of over 10,500 tests (as of version 2.5.3) that are executed across two distinct environments:

  1. The Local gas-fakes Emulator: This allows for rapid, isolated unit and integration testing of the simulated runtime, ensuring the internal logic and API contracts are sound.
  2. The Live Google Apps Script Environment: Crucially, every test suite is also executed against the actual, live GAS runtime.

This dual-environment verification ensures that the emulation is not merely "close," but behaviorally identical to production GAS, including the precise handling of complex error states, rate limiting, and obscure edge cases that only manifest in the live Google ecosystem.


2. Transparency and Auditing: The Documentation Layer

Beyond achieving functional parity, gas-fakes is engineered with a core commitment to engineering transparency. We recognize that for enterprise adoption, developers require not just a working emulator, but a fully auditable and self-documenting environment.

To address this, we have built a sophisticated documentation layer that provides unprecedented visibility into the emulation process.

📚 Embedded API Documentation

The repository includes a locally accessible and searchable version of the official Google Apps Script documentation. This documentation is integrated directly into the development environment, allowing developers to reference precise API definitions, parameter types, and expected behaviors without needing to switch context or leave their local codebase. This eliminates the friction of external documentation lookups, accelerating the development cycle while maintaining technical accuracy.

📊 Fidelity Progress Summary

To manage the monumental task of API parity, we provide an automated Fidelity Progress Summary. This system offers a clear, high-level overview of the implementation status for every class and method across all supported services. Developers can instantly see whether a specific function is Completed, In Progress, or Not Started, providing a transparent roadmap of the emulation effort and allowing them to gauge the maturity of the API they are using.

As of version 2.5.3, 4399 of Apps Scripts total of 6708 are implemented.

🔍 Deep Implementation Links: The Audit Trail

A unique feature of gas-fakes is deep implementation transparency. The documentation includes direct, clickable links to the exact line of source code where every single method is implemented within the emulator. This feature allows for instant verification and auditing of the emulation logic. If a developer questions the behavior of SpreadsheetApp.getRange(), they can instantly trace the call through the documentation to the specific line of code in gas-fakes that dictates its behavior, providing a high level of trust and debuggability.


3. Beyond Parity: The gas-fakes Advantage

While achieving parity is a huge task, another value of gas-fakes lies in the capabilities it enables. Capabilities that are fundamentally impossible or prohibitively difficult within the constraints of the live Google Apps Script environment. This includes the elimination of theat troublesome 6 minute execution time limit on Live Apps Script.

gas-fakes transforms the Apps Script language into a modern application development platform by separating its syntax from the place it traditionally runs.

🚀 GAS Syntax for Regular Node Apps: Simplified Workspace Access

A transformative features of gas-fakes is its ability to inject the familiar, high-level syntax of Google Apps Script directly into a standard Node.js runtime.

Even if you have no intention of ever deploying to Google Apps Script, you can use the simple, intuitive GAS syntax (e.g., SpreadsheetApp, DriveApp) in your regular Node.js apps. This provides a much simpler interface for accessing Workspace resources compared to the complex, low-level parameters of the raw REST APIs. It reduces cognitive load, improves maintainability, and abstracts away the complexity of OAuth scopes and request formatting.

🔑 Auth Provisioning & Token Reuse: A Unified Credential Manager

Managing authentication tokens across multiple services is an operational burden. gas-fakes auth acts as a powerful, centralized credential manager. It provisions OAuth tokens for multiple backends (Google, KSuite, MS Graph) scoped to your provided manifest which can then be easily retrieved and reused by other parts of your Node application or even by separate CLI tools. This creates a streamlined, single source of truth for credentials.

☁️ Containerization and Multi-Cloud Deployment

The entire GAS runtime emulation can be packaged using Docker. This allows developers to deploy and run GAS-like logic in modern, serverless, and scalable multi-cloud environments. By leveraging the container image, gas-fakes is fully compatible with leading cloud platforms, including:

  • Google Cloud Run, Azure Container Apps, AWS Lambda, IBM Cloud, and Kubernetes.

This capability fundamentally breaks the vendor lock-in associated with proprietary GAS deployment, allowing the same business logic to be executed in any serverless or containerized architecture.

🚀 CLI Workflow and Initialization

While the core functionality of gas-fakes provides a local execution environment, the initial setup and integration with live cloud services are handled through a streamlined Command Line Interface (CLI). This workflow is designed to minimize friction, automate complex configuration tasks, and ensure that your local testing environment perfectly mirrors the permissions and dependencies of your production Apps Script project.

🛠️ Streamlined Project Setup (gas-fakes init)

The gas-fakes init command serves as the foundational step for any new project. It automates the tedious process of environment configuration, allowing developers to focus immediately on coding. It automatically generates a local .env file, which securely stores necessary configuration variables and prompts the user to select the target cloud backends (e.g., Google Workspace, KSuite, MS Graph).

🔑 Authentication and Token Management (gas-fakes auth)

Connecting a local environment to live cloud services requires managing complex OAuth flows and token lifecycles. The gas-fakes auth command abstracts this complexity, providing a robust mechanism for secure, persistent authentication across all supported backends. It handles initial authorization guiding the user through browser redirects and manages secure token storage and refresh logic.

🔬 Automatic Scope Discovery: Precision Permissions

The CLI automatically reads the appsscript.json manifest file from your project. By parsing this file, gas-fakes automatically infers and registers the exact OAuth scopes necessary for local execution. This ensures that your local environment is provisioned with the precise permissions required by the live project, guaranteeing parity without requiring developers to manually track or update scope lists.

gas-fakes even supports existing published Apps Script libraries. If they are mentioned in your manifest, they can be accessed remotely from live Apps Script and executed locally.

🚀 Local Web Server and RPC Testing

In live GAS, testing a Web App requires deployment and a live URL. In gas-fakes, you can use its cli to instantiate the entire GAS environment locally, deploy your code to a simulated endpoint, and test complex google.script.run interactions and HTML Service templating with full local debugging tools without the need for any actual deployments. This accelerates the development feedback loop, with code changes showing up live in your local environment.

🌐 Multi-Backend Architecture

Live GAS is tightly coupled to Google services. gas-fakes decouples the business logic from the data source. By simply switching a configuration property, your GAS-like code can run against Google Services, KSuite, or MS Graph. This enables hybrid architectures and sovereign cloud, with increased parity for non-Google backends currently being prioritized.

🧠 The Automation Layer: CLI, gf_agent, and togas

While the sandbox provides the secure environment, the gas-fakes CLI and the specialized gf_agent provide the intelligence and accessibility needed for modern automation.

  • The CLI: A robust command-line tool for running scripts, starting local servers, and managing the sandbox.
  • gf_agent: This AI-powered companion acts as a translator, bridging the gap between natural language intent and executable code. For example, a request like "Summarize my last 5 emails and put them in a new spreadsheet" is instantly converted into optimized Apps Script and executed by your AI agent. This is a self learning skills agaent which can both enhance its own knowledge, and optionally contribute towards community skills.
  • togas & Clasp Integration: The togas command acts as a high-level orchestrator for deployment. It automates the process of bundling and synchronizing local files with a live GAS project. It builds upon and enhances the core functionality of clasp, providing a streamlined local-to-cloud workflow and making the necessary adjustments to local 'Node specific' ES syntax.
  • Sandbox-Agent Synergy: This combination enables safe, instant Workspace automation. The agent handles the what, and the sandbox ensures the how, guaranteeing that code only touches whitelisted resources without the overhead of building complex specialized agents or MCP servers.

🛠️ Modern Tooling and Developer Experience

A big pain point for GAS developers is the lack of modern tooling. gas-fakes eliminates this by providing a full Node.js development stack:

  • NPM Ecosystem: Utilize any modern NPM package, allowing access to thousands of specialized libraries.
  • Advanced Debugging: Leverage industry-standard Node.js debuggers (e.g., VS Code, AntiGravity) to step through code, inspect variables, and trace execution paths—a luxury unavailable in the GAS runtime—while simultaneously inspecting client-side HTML Service code in the Chrome debugger in its original structure, line numberings and format.

🛡️ Granular Sandbox and Security

The live GAS environment offers a broad permission model. gas-fakes provides a fine-grained, developer-controlled sandbox:

  • File-Level Whitelisting: Define exactly which files or modules the script is allowed to access.
  • Service-Level Permission Controls: Explicitly define which simulated services (e.g., GmailApp, DriveApp) the script is permitted to call, allowing for highly secure, auditable execution environments.

This optional level of granularity gives protection against Vibe coding hallucination.

🔗 Hybrid Interoperability: Bridging Local and Live

You often need to maintain state across environments. gas-fakes supports Hybrid Interoperability.

By integrating with external services like Redis or Upstash, gas-fakes allows the local development environment to share cache data, properties, and session state with the live, deployed GAS instance. This means your local tests are not isolated; they are running against a realistic, persistent state, ensuring seamless transition from development to production. We provide a drop-in replacement property and cache service library for live Apps Script, so you can share exactly the same stores between your local environment and the live deployed GAS.


Conclusion: Apps Script as a 'Lingua Franca'

gas-fakes elevates Apps Script, a powerful yet constrained scripting language, to the level of a modern, maintainable, and scalable application framework—a lingua franca for Google Workspace integration. It allows teams to write the code they know, test it with the fidelity they require, and deploy it with the control they deserve.

We are not just emulating GAS; we are liberating it.

Links

This full article
This repo

Top comments (0)